From 14df85a782a060c4fa7eee05af15b57220a627f9 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Mon, 3 Nov 2003 11:04:22 +0000 Subject: fix logic wrt pkgstems and dependencies. ok sturm@ --- usr.sbin/pkg_add/pkg_delete | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete index f0e7f6e614a..0fada87788b 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.6 2003/10/28 17:26:01 espie Exp $ +# $OpenBSD: pkg_delete,v 1.7 2003/11/03 11:04:21 espie Exp $ # # Copyright (c) 2003 Marc Espie. # @@ -291,15 +291,12 @@ $state->{verbose} = $opt_v; $state->{extra} = $opt_c; $ENV{'PKG_DELETE_EXTRA'} = $state->{extra} ? "Yes" : "No"; -my (%toremove, %extra_rm); +# First, resolve pkg names + +my @realnames; my $bad; -for my $pkgname (@ARGV) { - $toremove{$pkgname} = 1; -} -my @todo; -push(@todo, @ARGV); -while (my $pkgname = pop @todo) { +for my $pkgname (@ARGV) { unless (is_installed($pkgname)) { if (OpenBSD::PackageName::is_stem($pkgname)) { my @l = OpenBSD::PackageName::findstem($pkgname, @@ -314,6 +311,19 @@ while (my $pkgname = pop @todo) { } } next unless is_installed($pkgname); + push(@realnames, $pkgname); +} + +# Then check that dependencies are okay +my (%toremove, %extra_rm); +my @todo; +for my $pkgname (@realnames) { + $toremove{$pkgname} = 1; +} + +push(@todo, @realnames); + +while (my $pkgname = pop @todo) { my $deps = OpenBSD::RequiredBy->new($pkgname)->list(); if (@$deps > 0) { for my $dep (@$deps) { @@ -332,20 +342,11 @@ if ($bad) { exit(1); } +# and finally, handle the removal { do { $removed = 0; - for my $pkgname (@ARGV) { + for my $pkgname (@realnames) { next if $done{$pkgname}; - unless (is_installed($pkgname)) { - if (OpenBSD::PackageName::is_stem($pkgname)) { - my @l = OpenBSD::PackageName::findstem($pkgname, installed_packages()); - if (@l == 1) { - $pkgname = $l[0]; - } elsif (@l != 0) { - print "Ambiguous: $pkgname could be ", join(' ', @l),"\n"; - } - } - } unless (is_installed($pkgname)) { print "$pkgname was not installed\n"; $done{$pkgname} = 1; -- cgit v1.2.3