diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2005-08-17 18:44:25 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2005-08-17 18:44:25 +0000 |
commit | 222d84b3b2ed749c672f61c543c2e33b34a0daaf (patch) | |
tree | c3d48a4a9cfacb89bc381cde8d44e741c6c1b290 /usr.sbin | |
parent | 4035f6fab1ffb2f995ff5d45a0ee8199ada2fb55 (diff) |
reuse compute_closure
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/pkg_delete | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete index 4d3944a00d6..93a176dfdcc 100644 --- a/usr.sbin/pkg_add/pkg_delete +++ b/usr.sbin/pkg_add/pkg_delete @@ -1,6 +1,6 @@ #!/usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_delete,v 1.89 2005/08/17 18:37:10 espie Exp $ +# $OpenBSD: pkg_delete,v 1.90 2005/08/17 18:44:24 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -140,25 +140,13 @@ for my $pkgname (@ARGV) { } } -# Then check that dependencies are okay -my (%toremove, %extra_rm); -my @todo; -for my $pkgname (@realnames) { - $toremove{$pkgname} = 1; -} - -push(@todo, @realnames); +my @todo = OpenBSD::RequiredBy->compute_closure(@realnames); -while (my $pkgname = pop @todo) { - for my $dep (OpenBSD::RequiredBy->new($pkgname)->list()) { - next if defined $toremove{$dep}; - next if defined $extra_rm{$dep}; - $extra_rm{$dep}=$pkgname; - push(@todo, $dep); +if (@todo > @realnames) { + my %extra_rm = map {($_,1)} @todo; + for my $p (@realnames) { + delete $extra_rm{$p}; } -} - -if (keys(%extra_rm) != 0) { print "Can't remove ", join(' ', @ARGV), " without also removing:\n", join(' ', keys(%extra_rm)), "\n"; if ($forced{dependencies}) { @@ -167,7 +155,6 @@ if (keys(%extra_rm) != 0) { } else { print "(removing it as well)\n"; } - push(@realnames, keys(%extra_rm)); } else { $bad = 1; } @@ -181,7 +168,7 @@ eval { # and finally, handle the removal { do { $removed = 0; - DELETE: for my $pkgname (@realnames) { + DELETE: for my $pkgname (@todo) { next if $done{$pkgname}; unless (is_installed($pkgname)) { print "$pkgname was not installed\n"; |