summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2003-11-03 11:04:22 +0000
committerMarc Espie <espie@cvs.openbsd.org>2003-11-03 11:04:22 +0000
commit14df85a782a060c4fa7eee05af15b57220a627f9 (patch)
treef2b51800bcb8eee96647afa05b12c9b57b0132db
parent0a7b3aa640fe55ad16d2b33a5bb3dfa84eb0b040 (diff)
fix logic wrt pkgstems and dependencies.
ok sturm@
-rw-r--r--usr.sbin/pkg_add/pkg_delete39
1 files 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,21 +342,12 @@ 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;
$removed++;