summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rpm-find-leaves36
-rw-r--r--urpm/select.pm37
2 files changed, 43 insertions, 30 deletions
diff --git a/rpm-find-leaves b/rpm-find-leaves
index e8c544ba..731e8e5b 100644
--- a/rpm-find-leaves
+++ b/rpm-find-leaves
@@ -4,6 +4,7 @@ use strict;
use urpm;
use urpm::msg;
+use urpm::select;
my %options = (
restrict_group => 0,
@@ -40,39 +41,14 @@ while ($_ = shift) {
print $usage; exit 1;
}
-my @packages;
-{
- my $db = urpm::db_open_or_die_($urpm) or die "Can't open RPM db\n";
- $db->traverse(sub {
- my ($p) = @_;
- $p->pack_header;
- push @packages, $p;
- });
-}
-
-my %l;
-my %provides;
-foreach my $pkg (@packages) {
- next if $options{restrict_group} && $pkg->group !~ /\Q$options{group}/oi;
- $l{$pkg->name} = $pkg;
- push @{$provides{$_}}, $pkg foreach $pkg->provides_nosense;
-}
-
-foreach my $pkg (@packages) {
- foreach my $prop ($pkg->requires) {
- my ($n, $s) = URPM::property2name_range($prop);
- foreach my $p (@{$provides{$n} || []}) {
- $p != $pkg && $p->provides_overlap($prop) and
- delete $l{$p->name};
- }
- }
-}
+my $discard = $options{restrict_group} && sub { $_[0]->group !~ /\Q$options{group}/oi };
+my $leaves = urpm::select::installed_leaves($urpm, $discard);
if ($options{fullname}) {
- foreach my $k (sort keys %l) {
- my $l = $l{$k};
+ foreach my $k (sort keys %$leaves) {
+ my $l = $leaves->{$k};
print $l->name, '-', $l->version, '-', $l->release, '.', $l->arch, "\n";
}
} else {
- print "$_\n" foreach sort keys %l;
+ print "$_\n" foreach sort keys %$leaves;
}
diff --git a/urpm/select.pm b/urpm/select.pm
index dc663d6f..60f35317 100644
--- a/urpm/select.pm
+++ b/urpm/select.pm
@@ -602,5 +602,42 @@ sub translate_why_removed_one {
$fullname . ($s ? "\n ($s)" : '');
}
+sub installed_packages_packed {
+ my ($urpm) = @_;
+
+ my $db = urpm::db_open_or_die_($urpm) or die "Can't open RPM db\n";
+ my @l;
+ $db->traverse(sub {
+ my ($pkg) = @_;
+ $pkg->pack_header;
+ push @l, $pkg;
+ });
+ \@l;
+}
+
+sub installed_leaves {
+ my ($urpm, $o_discard) = @_;
+
+ my $packages = installed_packages_packed($urpm);
+
+ my (%l, %provides);
+ foreach my $pkg (@$packages) {
+ next if $o_discard && $o_discard->($pkg);
+ $l{$pkg->name} = $pkg;
+ push @{$provides{$_}}, $pkg foreach $pkg->provides_nosense;
+ }
+
+ foreach my $pkg (@$packages) {
+ foreach my $prop ($pkg->requires) {
+ my ($n, $s) = URPM::property2name_range($prop);
+ foreach my $p (@{$provides{$n} || []}) {
+ $p != $pkg && $p->provides_overlap($prop) and
+ delete $l{$p->name};
+ }
+ }
+ }
+
+ \%l;
+}
1;