diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2005-08-29 00:42:59 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2005-08-29 00:42:59 +0000 |
commit | f77900a9dce364865e138dff23d50042e10dd159 (patch) | |
tree | a435826b87769ea6fdd6c508250e843e9b2e2989 /usr.sbin | |
parent | b3f05d04e18121aab8fa11d1cbc48691bcef59cc (diff) |
correctly trim old p* versions of packages.
tests sturm@, aanriot@
okay deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageName.pm | 42 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 29 |
2 files changed, 43 insertions, 28 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageName.pm b/usr.sbin/pkg_add/OpenBSD/PackageName.pm index d8ed3bf9fa6..4805d3596ca 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageName.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageName.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageName.pm,v 1.8 2005/08/16 11:25:48 espie Exp $ +# $OpenBSD: PackageName.pm,v 1.9 2005/08/29 00:42:58 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -57,6 +57,46 @@ sub is_stem } } +sub splitp +{ + local $_ = shift; + + if (/^(.*\-\d[^-]*)p(\d+)/) { + return ($1.$', $2); + } else { + return ($_,-1); + } +} + +sub rebuildp +{ + my ($pkg, $p) = @_; + if ($p == -1) { + return $pkg; + } + if ($pkg =~ m/\-\d[^-]*/) { + return "$`$&p$p$'"; + } else { + return $pkg."p".$p; + } +} + +sub keep_most_recent +{ + my $h = {}; + for my $pkgname (@_) { + my ($p, $v) = splitp($pkgname); + if (!defined $h->{$p} || $h->{$p} < $v) { + $h->{$p} = $v; + } + } + my @list = (); + while (my ($p, $v) = each %$h) { + push(@list, rebuildp($p, $v)); + } + return @list; +} + sub findstem { my ($k, @list) = @_; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index e0e056ca427..ee60c8c694e 100644 --- a/usr.sbin/pkg_add/pkg_add +++ b/usr.sbin/pkg_add/pkg_add @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_add,v 1.195 2005/08/22 12:18:06 espie Exp $ +# $OpenBSD: pkg_add,v 1.196 2005/08/29 00:42:58 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -635,33 +635,8 @@ sub find_updates print "Updating $pkgname -> ", join(' ', @l2), "\n"; # if all packages have the same version, but distinct p, # grab the most recent. - # XXX dirty as hell, clean-up after 3.8 if (@l2 > 1) { - my ($bestbase, $bestp, $best); - my ($base, $p); - for my $i (@l2) { - if ($i =~ m/p(\d+)$/) { - $base = $`; - $p = $1; - } else { - $base = $i; - $p = -1; - } - if (!defined $bestbase) { - ($bestbase, $bestp, $best) = ($base, $p, $i); - } else { - if ($base ne $bestbase) { - undef $best; - last; - } - if ($p > $bestp) { - ($bestp, $best) = ($p, $i); - } - } - } - if (defined $best) { - @l2 = ($best); - } + @l2 = OpenBSD::PackageName::keep_most_recent(@l2); } if (@l2 == 1) { |