diff options
Diffstat (limited to 'urpme')
-rw-r--r-- | urpme | 56 |
1 files changed, 34 insertions, 22 deletions
@@ -20,12 +20,13 @@ use strict; #use strict qw(subs vars refs); +use rpmtools; use urpm; #- get I18N translation method. import urpm _; -my ($auto, $matches, $maymatch, %provides, @l, @m, @toremove); +my ($auto, $matches, $maymatch, @l, @m, @toremove); my $askok = _("Is it OK?"); my $askrm = _("Remove them all?"); # Translator: Add here the keys which might be pressed in the "No"-case. @@ -43,8 +44,6 @@ if ( / --?h/ || @ARGV == 0 ) { $matches = / -a /; $auto = / --?auto /; -my $DIR = "/var/lib/urpmi"; - @l = grep { !/^-/ } @ARGV; if (!$matches) { @m = map { chop; $_ } `rpm -q @l 2>&1`; @@ -65,10 +64,7 @@ if ($matches || $maymatch) { } } -load_provides(); -my %toremove; -@toremove{$_, @{$provides{$_} || []}} = () foreach @m; - +my %toremove; @toremove{@m} = (); my $changed = 1; while ($changed) { $changed = 0; @@ -87,6 +83,37 @@ if ( ! (@toremove = keys %toremove) ) { print _("Nothing to remove.\n"); exit(0); } + +#- check if a package to be removed is a part of basesystem requires. +my %base; +my @base = qw(basesystem); +my %basepackages; +my $db = rpmtools::db_open(''); +while (defined($_ = shift @base)) { + exists $basepackages{$_} and next; + rpmtools::db_traverse_tag($db, /^\// ? 'path' : 'whatprovides', [ $_ ], [ qw(name version release requires) ], sub { + my ($p) = @_; + push @{$basepackages{$_} ||= []}, "$p->{name}-$p->{version}-$p->{release}"; + push @base, @{$p->{requires} || []}; + }); +} +rpmtools::db_close($db); +foreach (values %basepackages) { + my $n = @$_; + foreach (@$_) { + $base{$_} = \$n; + } +} +my $base_str = ''; +foreach (@toremove) { + my $rn = $base{$_}; + if ($rn) { + $$rn == 1 and $base_str .= _("removing package %s will break your system\n", $_); + --$$rn; + } +} +$base_str and die $base_str; + if (@toremove > @l && !$auto) { my $sum = 0; map { $sum += $_ } `rpm -q --queryformat "%{SIZE}\n" @toremove`; @@ -97,21 +124,6 @@ if (@toremove > @l && !$auto) { system("rpm", "-e", @toremove); -sub load_provides { - local *F; - open F, "$DIR/depslist.ordered" or return; - my @packages_id; - my %provides_id; - foreach (<F>) { - my ($p, $size, @l) = split; - #$size{$p} = $size; - push @packages_id, $p; - push @{$provides_id{$_}}, $p foreach @l; - } - foreach (keys %provides_id) { - $provides{$packages_id[$_]} = $provides_id{$_}; - } -} sub toMb { my $nb = $_[0] / 1024 / 1024; int $nb + 0.5; |