On 04/15/15 17:56, Marc Espie wrote:
was requested by sthen@

works with pkg.conf and PKG_PATH, similar sequences as for dpb:

%a -> architecture
%c -> either snapshots or version number
%v -> always version number.

please test/comment

just tried it after rewriting:

installpath = http://ftp.fr.openbsd.org/pub/OpenBSD/%c/packages/%a/

in pkg.conf

Index: OpenBSD/PackingElement.pm
===================================================================
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PackingElement.pm,v
retrieving revision 1.239
diff -u -p -r1.239 PackingElement.pm
--- OpenBSD/PackingElement.pm   25 Feb 2015 16:37:15 -0000      1.239
+++ OpenBSD/PackingElement.pm   15 Apr 2015 15:53:09 -0000
@@ -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;
  }
Index: OpenBSD/PackageRepository/Installed.pm
===================================================================
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm,v
retrieving revision 1.29
diff -u -p -r1.29 Installed.pm
--- OpenBSD/PackageRepository/Installed.pm      15 Jun 2014 23:49:51 -0000      
1.29
+++ OpenBSD/PackageRepository/Installed.pm      15 Apr 2015 15:53:09 -0000
@@ -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';

I've seen at least -beta versions short before release locks. Not
sure if there are -alpha too? Those should be treated
same way as snapshots, I think.


+                               } 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;
  }


Reply via email to