commit expanded tags for %c, %v, %a
authorespie <espie@openbsd.org>
Thu, 16 Apr 2015 09:32:23 +0000 (09:32 +0000)
committerespie <espie@openbsd.org>
Thu, 16 Apr 2015 09:32:23 +0000 (09:32 +0000)
usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm
usr.sbin/pkg_add/OpenBSD/PackingElement.pm

index e9e5090..87e87e9 100644 (file)
@@ -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 <espie@openbsd.org>
 #
@@ -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;
 }
index e787231..7e81553 100644 (file)
@@ -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 <espie@openbsd.org>
 #
@@ -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;
 }