From f77900a9dce364865e138dff23d50042e10dd159 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Mon, 29 Aug 2005 00:42:59 +0000 Subject: correctly trim old p* versions of packages. tests sturm@, aanriot@ okay deraadt@ --- usr.sbin/pkg_add/OpenBSD/PackageName.pm | 42 ++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'usr.sbin/pkg_add/OpenBSD') 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 # @@ -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) = @_; -- cgit v1.2.3