summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2010-01-09 12:01:58 +0000
committerMarc Espie <espie@cvs.openbsd.org>2010-01-09 12:01:58 +0000
commit1b253600a654ecbe35bb1fa8a3085a3ffffd0d08 (patch)
tree20e9c23b1d5e779cf9cf70c8631694d1589ad404 /usr.sbin/pkg_add/OpenBSD
parent41e450e6bfa5b38165aed04d70496e8dbbb7a6d2 (diff)
fixed version, somehow I forgot that I use parse to do weird things with
PKG_PATH...
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageLocator.pm22
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository.pm105
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm41
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm4
4 files changed, 93 insertions, 79 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm b/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm
index 52d4b6f888a..5e4f7264329 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageLocator.pm,v 1.81 2010/01/09 11:26:58 espie Exp $
+# $OpenBSD: PackageLocator.pm,v 1.82 2010/01/09 12:01:57 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -45,20 +45,12 @@ if (defined $ENV{PKG_PATH}) {
sub path_parse
{
- use File::Basename;
- use OpenBSD::Paths;
- my $pkg_db = $ENV{"PKG_DBDIR"} || OpenBSD::Paths->pkgdb;
-
- my ($pkgname, $path) = fileparse(shift);
- my $repo;
-
- if ($path eq $pkg_db.'/') {
- $repo = OpenBSD::PackageRepository::Installed->new;
- } else {
- $repo = OpenBSD::PackageRepository->new($path);
+ my ($pkgname, $path) = (shift, './');
+ if ($pkgname =~ m/^(.*[\/\:])(.*)/) {
+ ($pkgname, $path) = ($2, $1);
}
- return ($repo, $path, $pkgname);
+ return (OpenBSD::PackageRepository->new($path), $path, $pkgname);
}
sub find
@@ -69,7 +61,7 @@ sub find
return $packages{$_};
}
my $package;
- if (m/\//o) {
+ if (m/[\/\:]/o) {
my ($repository, undef, $pkgname) = path_parse($_);
$package = $repository->find($pkgname, $arch);
if (defined $package) {
@@ -87,7 +79,7 @@ sub grabPlist
my ($class, $_, $arch, $code) = @_;
my $plist;
- if (m/\//o) {
+ if (m/[\/\:]/o) {
my ($repository, undef, $pkgname) = path_parse($_);
$plist = $repository->grabPlist($pkgname, $arch, $code);
if (defined $plist) {
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
index 1c9c9a052ef..6297ea6a661 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageRepository.pm,v 1.74 2010/01/09 11:26:58 espie Exp $
+# $OpenBSD: PackageRepository.pm,v 1.75 2010/01/09 12:01:57 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -30,13 +30,6 @@ our @ISA=(qw(OpenBSD::PackageRepositoryBase));
use OpenBSD::PackageLocation;
use OpenBSD::Paths;
-sub _new
-{
- my ($class, $path, $host) = @_;
- $path .= '/' unless $path =~ m/\/$/;
- bless { host => $host, path => $path }, $class;
-}
-
sub baseurl
{
my $self = shift;
@@ -48,42 +41,17 @@ sub new
{
my ($class, $baseurl) = @_;
my $o = $class->parse(\$baseurl);
- return $o;
-}
-
-sub strip_urlscheme
-{
- my ($class, $r) = @_;
- if ($$r =~ m/^(.*?)\:(.*)$/) {
- my $scheme = lc($1);
- if ($scheme eq $class->urlscheme) {
- $$r = $2;
- return 1;
- }
- }
- return 0;
-}
-
-sub parse_local_url
-{
- my ($class, $r, @args) = @_;
-
- my $o;
-
- if ($$r =~ m/^(.*?)\:(.*)/) {
- $o = $class->_new($1, @args);
- $$r = $2;
- } else {
- $o = $class->_new($$r, @args);
- $$r = '';
+ if ($baseurl ne '') {
+ return undef;
}
return $o;
}
-sub parse_url
-{
- &parse_local_url;
-}
+# we have to pass a reference because we want to:
+# - strip the scheme
+# - report whether we stripped it
+# (relevant for file: url, where we strip, but don't care if we did
+# vs other schemes, where not having the ftp: marker is a problem)
sub parse_fullurl
{
@@ -95,30 +63,32 @@ sub parse_fullurl
sub parse
{
- my ($class, $ref) = @_;
- my $_ = $$ref;
+ my ($class, $r) = @_;
+ my $_ = $$r;
return undef if $_ eq '';
if (m/^ftp\:/io) {
- return OpenBSD::PackageRepository::FTP->parse_fullurl($ref);
+ return OpenBSD::PackageRepository::FTP->parse_fullurl($r);
} elsif (m/^http\:/io) {
- return OpenBSD::PackageRepository::HTTP->parse_fullurl($ref);
+ return OpenBSD::PackageRepository::HTTP->parse_fullurl($r);
} elsif (m/^https\:/io) {
- return OpenBSD::PackageRepository::HTTPS->parse_fullurl($ref);
+ return OpenBSD::PackageRepository::HTTPS->parse_fullurl($r);
} elsif (m/^scp\:/io) {
require OpenBSD::PackageRepository::SCP;
- return OpenBSD::PackageRepository::SCP->parse_fullurl($ref);
+ return OpenBSD::PackageRepository::SCP->parse_fullurl($r);
} elsif (m/^src\:/io) {
require OpenBSD::PackageRepository::Source;
- return OpenBSD::PackageRepository::Source->parse_fullurl($ref);
+ return OpenBSD::PackageRepository::Source->parse_fullurl($r);
} elsif (m/^file\:/io) {
- return OpenBSD::PackageRepository::Local->parse_fullurl($ref);
+ return OpenBSD::PackageRepository::Local->parse_fullurl($r);
} elsif (m/^inst\:$/io) {
- return OpenBSD::PackageRepository::Installed->parse_fullurl($ref);
+ return OpenBSD::PackageRepository::Installed->parse_fullurl($r);
+ } elsif (m/^pipe\:$/io) {
+ return OpenBSD::PackageRepository::Local::Pipe->parse_fullurl($r);
} else {
- return OpenBSD::PackageRepository::Local->parse_fullurl($ref);
+ return OpenBSD::PackageRepository::Local->parse_fullurl($r);
}
}
@@ -274,12 +244,28 @@ sub urlscheme
return 'file';
}
+my $pkg_db;
+
+sub pkg_db
+{
+ if (!defined $pkg_db) {
+ use OpenBSD::Paths;
+ $pkg_db = $ENV{"PKG_DBDIR"} || OpenBSD::Paths->pkgdb;
+ }
+ return $pkg_db;
+}
+
sub parse_fullurl
{
my ($class, $r) = @_;
- $class->strip_urlscheme($r);
- return $class->parse_local_url($r);
+ my $ok = $class->strip_urlscheme($r);
+ my $o = $class->parse_url($r);
+ if (!$ok && $o->{path} eq $class->pkg_db()."/") {
+ return OpenBSD::PackageRepository::Installed->new;
+ } else {
+ return $o;
+ }
}
# wrapper around copy, that sometimes does not copy
@@ -407,18 +393,15 @@ sub baseurl
sub parse_url
{
- &parse_distant_url;
-}
-
-sub parse_distant_url
-{
my ($class, $r) = @_;
# same heuristics as ftp(1):
# find host part, rest is parsed as a local url
- if ($$r =~ m/^\/\/(.*?)(\/.*)$/) {
- my $host = $1;
- $$r = $2;
- return $class->parse_local_url($r, $host);
+ if (my ($host, $path) = $$r =~ m/^\/\/(.*?)(\/.*)$/) {
+
+ $$r = $path;
+ my $o = $class->SUPER::parse_url($r);
+ $o->{host} = $host;
+ return $o;
} else {
return undef;
}
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm
index c26458a5def..11373d09655 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.18 2010/01/09 11:26:58 espie Exp $
+# $OpenBSD: Installed.pm,v 1.19 2010/01/09 12:01:57 espie Exp $
#
# Copyright (c) 2007 Marc Espie <espie@openbsd.org>
#
@@ -26,6 +26,45 @@ use warnings;
package OpenBSD::PackageRepositoryBase;
+sub parse_url
+{
+ my ($class, $r) = @_;
+
+ my $path;
+
+ if ($$r =~ m/^(.*?)\:(.*)/) {
+ $path = $1;
+ $$r = 2;
+ } else {
+ $path = $$r;
+ $$r = '';
+ }
+
+ $path .= '/' unless $path =~ m/\/$/;
+ bless { path => $path }, $class;
+}
+
+sub parse_fullurl
+{
+ my ($class, $_) = @_;
+
+ $class->strip_urlscheme($_) or return undef;
+ return $class->parse_url($_);
+}
+
+sub strip_urlscheme
+{
+ my ($class, $r) = @_;
+ if ($$r =~ m/^(.*?)\:(.*)$/) {
+ my $scheme = lc($1);
+ if ($scheme eq $class->urlscheme) {
+ $$r = $2;
+ return 1;
+ }
+ }
+ return 0;
+}
+
sub match_locations
{
my ($self, $search, @filters) = @_;
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index ef4696fe818..94fb09e8920 100644
--- a/usr.sbin/pkg_add/OpenBSD/Update.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Update.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Update.pm,v 1.129 2010/01/09 11:26:58 espie Exp $
+# $OpenBSD: Update.pm,v 1.130 2010/01/09 12:01:57 espie Exp $
#
# Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org>
#
@@ -275,7 +275,7 @@ sub process_hint2
my ($self, $set, $hint, $state) = @_;
my $pkgname = $hint->pkgname;
if (OpenBSD::PackageName::is_stem($pkgname)) {
- if ($pkgname =~ m/\//o) {
+ if ($pkgname =~ m/[\/\:]/o) {
require OpenBSD::PackageLocator;
my $repo;
($repo, undef, $pkgname) = OpenBSD::PackageLocator::path_parse($pkgname);