summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2005-08-29 00:42:59 +0000
committerMarc Espie <espie@cvs.openbsd.org>2005-08-29 00:42:59 +0000
commitf77900a9dce364865e138dff23d50042e10dd159 (patch)
treea435826b87769ea6fdd6c508250e843e9b2e2989 /usr.sbin/pkg_add/OpenBSD
parentb3f05d04e18121aab8fa11d1cbc48691bcef59cc (diff)
correctly trim old p* versions of packages.
tests sturm@, aanriot@ okay deraadt@
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageName.pm42
1 files changed, 41 insertions, 1 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) = @_;