aboutsummaryrefslogtreecommitdiffstats
path: root/URPM/Signature.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2007-12-10 15:05:26 +0000
committerPascal Rigaux <pixel@mandriva.com>2007-12-10 15:05:26 +0000
commitdbcb537597b881246ac37f4a70de371d3ccda614 (patch)
tree4b1cc198a4d18c004f7af9d5390ea71c693ddcb0 /URPM/Signature.pm
parent54e360b2cfa968b21527f534dac595a356130a4a (diff)
downloadperl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.tar
perl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.tar.gz
perl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.tar.bz2
perl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.tar.xz
perl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.zip
- replace ->import_needed_pubkeys and ->import_pubkey in favor of
import_needed_pubkeys_from_file() and ->import_pubkey_file (! this breaks API !) - import_pubkey is dropped because it messes to much with rpmlib internals, whereas import_pubkey_file is plain simple - in Signature.pm, dropping compare_pubkeys() options (since they are not used anymore) - import_needed_pubkeys_from_file() may not do a clean job if the pubkey file contains more than one pubkey.
Diffstat (limited to 'URPM/Signature.pm')
-rw-r--r--URPM/Signature.pm49
1 files changed, 26 insertions, 23 deletions
diff --git a/URPM/Signature.pm b/URPM/Signature.pm
index 66f717b..4a0fdbe 100644
--- a/URPM/Signature.pm
+++ b/URPM/Signature.pm
@@ -5,12 +5,12 @@ use strict;
#- compare keys to avoid glitches introduced during the importation where
#- some characters may be modified on the fly by rpm --import...
sub compare_pubkeys {
- my ($a, $b, %options) = @_;
+ my ($a, $b) = @_;
my $diff = 0;
my @a = unpack "C*", $a->{content};
my @b = unpack "C*", $b->{content};
- #- default options to use.
+ my %options;
$options{start} ||= 0;
$options{end} ||= @a < @b ? scalar(@b) : scalar(@a);
$options{diff} ||= 1;
@@ -105,33 +105,36 @@ sub parse_pubkeys_ {
values %keys;
}
-#- import pubkeys only if it is needed.
+#- obsoleted
sub import_needed_pubkeys {
- my ($urpm, $l, %options) = @_;
+ warn "import_needed_pubkeys prototype has changed, please give a file directly\n";
+ return;
+}
- #- use the same database handle to avoid re-opening multiple times the database.
- my $db = $options{db};
- $db ||= URPM::DB::open($options{root}, 1)
- or die "Can't open RPM DB, aborting\n";
-
- #- assume $l is a reference to an array containing all the keys to import
- #- if needed.
- foreach my $k (@{$l || []}) {
- my ($id, $imported);
- foreach my $kv (values %{$urpm->{keys} || {}}) {
- compare_pubkeys($k, $kv, %options) == 0 and $id = $kv->{id}, last;
- }
- unless ($id) {
+#- import pubkeys only if it is needed.
+sub import_needed_pubkeys_from_file {
+ my ($db, $pubkey_file, $o_callback) = @_;
+
+ my @keys = parse_pubkeys_($db);
+
+ my $find_key = sub {
+ my ($k) = @_;
+ my ($kv) = grep { compare_pubkeys($k, $_) == 0 } @keys;
+ $kv && $kv->{id};
+ };
+
+ foreach my $k (parse_armored_file(undef, $pubkey_file)) {
+ my $imported;
+ my $id = $find_key->($k);
+ if (!$id) {
$imported = 1;
- import_pubkey(block => $k->{block}, db => $db);
- $urpm->parse_pubkeys(db => $db);
- foreach my $kv (values %{$urpm->{keys} || {}}) {
- compare_pubkeys($k, $kv, %options) == 0 and $id = $kv->{id}, last;
- }
+ import_pubkey_file($db, $pubkey_file);
+ @keys = parse_pubkeys_($db);
+ $id = $find_key->($k);
}
#- let the caller know about what has been found.
#- this is an error if the key is not found.
- $options{callback} and $options{callback}->($urpm, $db, $k, $id, $imported, %options);
+ $o_callback and $o_callback->($id, $imported);
}
}