summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-02-22 21:31:42 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-02-22 21:31:42 +0000
commita3d1b83eff15f96dc8a6514389533c06432d8876 (patch)
tree7c4bce6d57b1c7518255fe5c579067271f258938 /usr.sbin
parentf8a51c05bd2fcb8d2015be35d5e937fe89379a17 (diff)
Problem noticed by Henrik Hellerstedt <henrik@kohina.net>
Fix a really fun bug in pkg_delete: solve_installed_names has to normalize the list of names so that comparing its size vs. its transitive closure is meaningful. Use the classical hash + list to preserve the order. While we're there, use the hash to avoid asking the same questions again and again. After some back&forth with bernd. okay bernd@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageInfo.pm27
-rw-r--r--usr.sbin/pkg_add/pkg_delete4
2 files changed, 26 insertions, 5 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
index b8d9f410d7c..77209acef1d 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageInfo.pm,v 1.19 2007/02/17 10:39:35 sturm Exp $
+# $OpenBSD: PackageInfo.pm,v 1.20 2007/02/22 21:31:41 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -202,11 +202,15 @@ sub solve_installed_names
my $installed;
my $bad = 0;
+ my $seen = {};
for my $pkgname (@$old) {
$pkgname =~ s/\.tgz$//;
if (is_installed($pkgname)) {
- push(@$new, installed_name($pkgname));
+ if (!$seen->{$pkgname}) {
+ $seen->{$pkgname} = 1;
+ push(@$new, installed_name($pkgname));
+ }
} else {
if (OpenBSD::PackageName::is_stem($pkgname)) {
if (!defined $installed) {
@@ -217,18 +221,35 @@ sub solve_installed_names
print "Can't resolve $pkgname to an installed package name\n";
$bad = 1;
} elsif (@l == 1) {
- push(@$new, $l[0]);
+ if (!$seen->{$l[0]}) {
+ $seen->{$l[0]} = 1;
+ push(@$new, $l[0]);
+ }
} elsif (@l != 0) {
+ # try to see if we already solved the ambiguity
+ my $found = 0;
+ for my $p (@l) {
+ if ($seen->{$p}) {
+ $found = 1;
+ last;
+ }
+ }
+ next if $found;
+
print "Ambiguous: $pkgname could be ", join(' ', @l),"\n";
if ($state->{forced}->{ambiguous}) {
print "$msg\n";
push(@$new, @l);
+ for my $p (@l) {
+ $seen->{$p} = 1;
+ }
} else {
if ($state->{interactive}) {
require OpenBSD::ProgressMeter;
my $result = OpenBSD::Interactive::ask_list('Choose one package', 1, ("<None>", sort @l));
push(@$new, $result) if $result ne '<None>';
+ $seen->{$result} = 1;
} else {
$bad = 1;
}
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index bc594893338..74665f06345 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.94 2006/08/01 10:23:38 bernd Exp $
+# $OpenBSD: pkg_delete,v 1.95 2007/02/22 21:31:41 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -133,7 +133,7 @@ if (@todo > @realnames) {
for my $p (@realnames) {
delete $deps{$p};
}
- &$show([@ARGV], [keys %deps]);
+ &$show([@realnames], [keys %deps]);
if ((keys %deps) > 1 && OpenBSD::Interactive::confirm(
"Do you want details", $state->{interactive}, 1)) {
$details = 1;