From 300a433ff051b9148cfa1219e3109191f7d6c213 Mon Sep 17 00:00:00 2001 From: espie Date: Thu, 16 Apr 2015 09:32:23 +0000 Subject: [PATCH] commit expanded tags for %c, %v, %a --- .../OpenBSD/PackageRepository/Installed.pm | 37 ++++++++++++++++++- usr.sbin/pkg_add/OpenBSD/PackingElement.pm | 17 ++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm index e9e5090dd3a..87e87e9681e 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Installed.pm,v 1.29 2014/06/15 23:49:51 afresh1 Exp $ +# $OpenBSD: Installed.pm,v 1.30 2015/04/16 09:32:23 espie Exp $ # # Copyright (c) 2007-2014 Marc Espie # @@ -26,6 +26,40 @@ use warnings; package OpenBSD::PackageRepositoryBase; +my ($version, $current); + +sub expand_locations +{ + my ($class, $string, $state) = @_; + if ($string eq '%a') { + require OpenBSD::PackingElement; + return OpenBSD::PackingElement::Arch::arch(); + } else { + if (!defined $version) { + require OpenBSD::Paths; + open my $cmd, '-|', + OpenBSD::Paths->sysctl, '-n', 'kern.version'; + my $line = <$cmd>; + close($cmd); + if ($line =~ m/^OpenBSD (\d\.\d)(\S*)\s/) { + $version = $1; + if ($2 eq '-current') { + $current = 'snapshots'; + } else { + $current = $version; + } + } else { + $state->fatal("Can't figure out version"); + } + } + if ($string eq '%c') { + return $current; + } else { + return $version; + } + } +} + sub parse_url { my ($class, $r, $state) = @_; @@ -40,6 +74,7 @@ sub parse_url $$r = ''; } + $path =~ s/\%[vac]/$class->expand_locations($&, $state)/ge; $path .= '/' unless $path =~ m/\/$/; bless { path => $path, state => $state }, $class; } diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index e787231e610..7e8155307b7 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackingElement.pm,v 1.239 2015/02/25 16:37:15 sthen Exp $ +# $OpenBSD: PackingElement.pm,v 1.240 2015/04/16 09:32:23 espie Exp $ # # Copyright (c) 2003-2014 Marc Espie # @@ -1750,6 +1750,15 @@ sub stringize($) my ($machine_arch, $arch); +sub arch +{ + if (!defined $arch) { + my $cmd = OpenBSD::Paths->uname." -m"; + chomp($arch = `$cmd`); + } + return $arch; +} + sub check { my ($self, $forced_arch) = @_; @@ -1768,11 +1777,7 @@ sub check chomp($machine_arch = `$cmd`); } return 1 if $ok eq $machine_arch; - if (!defined $arch) { - my $cmd = OpenBSD::Paths->uname." -m"; - chomp($arch = `$cmd`); - } - return 1 if $ok eq $arch; + return 1 if $ok eq arch(); } return; } -- 2.20.1