From 7f1053179a772a944adf76a17b0d459bbdde662b Mon Sep 17 00:00:00 2001 From: Francois Pons Date: Tue, 19 Aug 2003 16:31:35 +0000 Subject: fixed URPM::import_armored_file to use internal XS function to import directly to database, handle importation of multiple keys by file. --- URPM/Signature.pm | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/URPM/Signature.pm b/URPM/Signature.pm index 7b90693..e2089e6 100644 --- a/URPM/Signature.pm +++ b/URPM/Signature.pm @@ -7,7 +7,8 @@ sub parse_pubkeys { my ($urpm, %options) = @_; my ($block, @l, $content); - my $db = URPM::DB::open($options{root}); + my $db = $options{db}; + $db ||= URPM::DB::open($options{root}); $db->traverse_tag('name', [ 'gpg-pubkey' ], sub { my ($p) = @_; @@ -59,8 +60,7 @@ sub parse_armored_file { } close F or die "unable to parse armored file $file"; - #- check only one key has been found. - @l > 1 and die "armored file contains more than one key"; + #- check at least one key has been found. @l < 1 and die "no key found while parsing armored file"; #- check if key has been found, remove from list. @@ -80,9 +80,26 @@ sub parse_armored_file { sub import_armored_file { my ($urpm, $file, %options) = @_; + local (*F, $_); + my $block = ''; - #- this is a tempory operation currently... - system("rpm", ($options{root} ? ("--root", $options{root}) : @{[]}), "--import", $file) == 0 or - die "import of armored file failed"; + #- read armored file. + open F, $file; + while () { + my $inside_block = /^-----BEGIN PGP PUBLIC KEY BLOCK-----$/ ... /^-----END PGP PUBLIC KEY BLOCK-----$/; + if ($inside_block) { + $block .= $_; + if ($inside_block =~ /E/) { + #- import key using the given database if any else the function will open the rpmdb itself. + #- FIXME workaround for rpm 4.2 if the rpmdb is left opened, the keys content are sligtly + #- modified by algorithms... + URPM::import_pubkey(block => $block, db => $options{db}, root => $options{root}) + or die "import of armored file failed"; + $block = ''; + } + } + } + close F or die "unable to parse armored file $file"; } + 1; -- cgit v1.2.1