reorg code, the arch/osversion code should live in a single place,
authorespie <espie@openbsd.org>
Thu, 16 Apr 2015 13:29:16 +0000 (13:29 +0000)
committerespie <espie@openbsd.org>
Thu, 16 Apr 2015 13:29:16 +0000 (13:29 +0000)
short and sweet

usr.sbin/pkg_add/OpenBSD/FwUpdate.pm
usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm
usr.sbin/pkg_add/OpenBSD/PackingElement.pm
usr.sbin/pkg_add/OpenBSD/Paths.pm

index efb023a..8403c85 100644 (file)
@@ -1,7 +1,7 @@
 #! /usr/bin/perl
 
 # ex:ts=8 sw=4:
-# $OpenBSD: FwUpdate.pm,v 1.17 2015/02/15 09:54:21 espie Exp $
+# $OpenBSD: FwUpdate.pm,v 1.18 2015/04/16 13:29:16 espie Exp $
 #
 # Copyright (c) 2014 Marc Espie <espie@openbsd.org>
 #
@@ -28,15 +28,9 @@ our @ISA = qw(OpenBSD::PkgAdd::State);
 sub find_path
 {
        my $state = shift;
-       open my $cmd, '-|', OpenBSD::Paths->sysctl, '-n', 'kern.version';
-       my $line = <$cmd>;
-       close($cmd);
-       if ($line =~ m/^OpenBSD (\d\.\d)(\S*)\s/) {
-               my ($version, $tag) = ($1, $2);
-               if ($tag eq '-current') {
-                       $version = 'snapshots';
-               }
-               $state->{path} = "http://firmware.openbsd.org/firmware/$version/";
+       my $dir = OpenBSD::Paths->os_directory;
+       if (defined $dir) {
+               $state->{path} = "http://firmware.openbsd.org/firmware/$dir/";
        } else {
                $state->fatal("Couldn't find/parse OS version");
        }
index 87e87e9..de0dff2 100644 (file)
@@ -1,5 +1,5 @@
 # ex:ts=8 sw=4:
-# $OpenBSD: Installed.pm,v 1.30 2015/04/16 09:32:23 espie Exp $
+# $OpenBSD: Installed.pm,v 1.31 2015/04/16 13:29:16 espie Exp $
 #
 # Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
 #
@@ -31,32 +31,13 @@ my ($version, $current);
 sub expand_locations
 {
        my ($class, $string, $state) = @_;
+       require OpenBSD::Paths;
        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;
-               }
+               return OpenBSD::Paths->architecture;
+       } elsif ($string eq '%v') {
+               return OpenBSD::Paths->os_version;
+       } elsif ($string eq '%c') {
+               return OpenBSD::Paths->os_directory;
        }
 }
 
index 7e81553..37008e1 100644 (file)
@@ -1,5 +1,5 @@
 # ex:ts=8 sw=4:
-# $OpenBSD: PackingElement.pm,v 1.240 2015/04/16 09:32:23 espie Exp $
+# $OpenBSD: PackingElement.pm,v 1.241 2015/04/16 13:29:16 espie Exp $
 #
 # Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
 #
@@ -1748,17 +1748,6 @@ sub stringize($)
        return join(',', @{$self->{arches}});
 }
 
-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) = @_;
@@ -1772,12 +1761,8 @@ sub check
                                next;
                        }
                }
-               if (!defined $machine_arch) {
-                       my $cmd = OpenBSD::Paths->arch." -s";
-                       chomp($machine_arch = `$cmd`);
-               }
-               return 1 if $ok eq $machine_arch;
-               return 1 if $ok eq arch();
+               return 1 if $ok eq OpenBSD::Paths->machine_architecture;
+               return 1 if $ok eq OpenBSD::Paths->architecture;
        }
        return;
 }
index 1530f8e..b49be5e 100644 (file)
@@ -1,5 +1,5 @@
 # ex:ts=8 sw=4:
-# $OpenBSD: Paths.pm,v 1.30 2014/08/26 17:47:24 jsing Exp $
+# $OpenBSD: Paths.pm,v 1.31 2015/04/16 13:29:16 espie Exp $
 #
 # Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
 #
@@ -74,4 +74,58 @@ sub font_cruft() { ("fonts.alias", "fonts.dir", "fonts.cache-1", "fonts.scale")
 sub man_cruft() { ("whatis.db", "mandoc.db", "mandoc.index") }
 sub info_cruft() { ("dir") }
 
+# a bit of code, OS-dependent stuff that's run-time detected and has no
+# home yet.
+
+my ($machine_arch, $arch, $osversion, $osdirectory);
+
+sub architecture
+{
+       if (!defined $arch) {
+               my $cmd = uname()." -m";
+               chomp($arch = `$cmd`);
+       }
+       return $arch;
+}
+
+sub machine_architecture
+{
+       if (!defined $machine_arch) {
+               my $cmd = arch()." -s";
+               chomp($machine_arch = `$cmd`);
+       }
+       return $machine_arch;
+}
+
+sub compute_osversion
+{
+       open my $cmd, '-|', OpenBSD::Paths->sysctl, '-n', 'kern.version';
+       my $line = <$cmd>;
+       close($cmd);
+       if ($line =~ m/^OpenBSD (\d\.\d)(\S*)\s/) {
+               $osversion = $1;
+               if ($2 eq '-current') {
+                       $osdirectory = 'snapshots';
+               } else {
+                       $osdirectory = $osversion;
+               }
+       }
+}
+
+sub os_version
+{
+       if (!defined $osversion) {
+               compute_osversion();
+       }
+       return $osversion;
+}
+
+sub os_directory
+{
+       if (!defined $osversion) {
+               compute_osversion();
+       }
+       return $osdirectory;
+}
+
 1;