diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-01-09 11:26:59 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-01-09 11:26:59 +0000 |
commit | 41e450e6bfa5b38165aed04d70496e8dbbb7a6d2 (patch) | |
tree | 89e2db8e84f41fd5392021825eb762f8ed477b7c /usr.sbin/pkg_add | |
parent | 88df32841fd0285d79a0c81f4db4765d75048564 (diff) |
temporary revert until I figure this out
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageLocator.pm | 22 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepository.pm | 114 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm | 30 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Update.pm | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_info | 4 |
5 files changed, 88 insertions, 86 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm b/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm index 5215985ca5c..52d4b6f888a 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.80 2010/01/09 10:59:48 espie Exp $ +# $OpenBSD: PackageLocator.pm,v 1.81 2010/01/09 11:26:58 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -45,12 +45,20 @@ if (defined $ENV{PKG_PATH}) { sub path_parse { - my ($pkgname, $path) = (shift, './'); - if ($pkgname =~ m/^(.*[\/\:])(.*)/) { - ($pkgname, $path) = ($2, $1); + 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); } - return (OpenBSD::PackageRepository->new($path), $path, $pkgname); + return ($repo, $path, $pkgname); } sub find @@ -61,7 +69,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) { @@ -79,7 +87,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 992a3f6e6e5..1c9c9a052ef 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.73 2010/01/09 10:59:48 espie Exp $ +# $OpenBSD: PackageRepository.pm,v 1.74 2010/01/09 11:26:58 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -30,6 +30,13 @@ 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; @@ -40,51 +47,78 @@ sub baseurl sub new { my ($class, $baseurl) = @_; - my $o = $class->parse($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 = ''; + } return $o; } -# 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_url +{ + &parse_local_url; +} sub parse_fullurl { - my ($class, $_) = @_; + my ($class, $r) = @_; - $class->strip_urlscheme(\$_) or return undef; - return $class->parse_url($_); + $class->strip_urlscheme($r) or return undef; + return $class->parse_url($r); } sub parse { - my ($class, $_) = @_; + my ($class, $ref) = @_; + my $_ = $$ref; return undef if $_ eq ''; if (m/^ftp\:/io) { - return OpenBSD::PackageRepository::FTP->parse_fullurl($_); + return OpenBSD::PackageRepository::FTP->parse_fullurl($ref); } elsif (m/^http\:/io) { - return OpenBSD::PackageRepository::HTTP->parse_fullurl($_); + return OpenBSD::PackageRepository::HTTP->parse_fullurl($ref); } elsif (m/^https\:/io) { - return OpenBSD::PackageRepository::HTTPS->parse_fullurl($_); + return OpenBSD::PackageRepository::HTTPS->parse_fullurl($ref); } elsif (m/^scp\:/io) { require OpenBSD::PackageRepository::SCP; - return OpenBSD::PackageRepository::SCP->parse_fullurl($_); + return OpenBSD::PackageRepository::SCP->parse_fullurl($ref); } elsif (m/^src\:/io) { require OpenBSD::PackageRepository::Source; - return OpenBSD::PackageRepository::Source->parse_fullurl($_); + return OpenBSD::PackageRepository::Source->parse_fullurl($ref); } elsif (m/^file\:/io) { - return OpenBSD::PackageRepository::Local->parse_fullurl($_); + return OpenBSD::PackageRepository::Local->parse_fullurl($ref); } elsif (m/^inst\:$/io) { - return OpenBSD::PackageRepository::Installed->parse_fullurl($_); - } elsif (m/^pipe\:$/io) { - return OpenBSD::PackageRepository::Local::Pipe->parse_fullurl($_); + return OpenBSD::PackageRepository::Installed->parse_fullurl($ref); } else { - return OpenBSD::PackageRepository::Local->parse_fullurl($_); + return OpenBSD::PackageRepository::Local->parse_fullurl($ref); } } @@ -240,28 +274,12 @@ 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, $_) = @_; + my ($class, $r) = @_; - my $r = $class->strip_urlscheme(\$_); - my $o = $class->parse_url($_); - if (!$r && $o->{path} eq $class->pkg_db()."/") { - return OpenBSD::PackageRepository::Installed->new; - } else { - return $o; - } + $class->strip_urlscheme($r); + return $class->parse_local_url($r); } # wrapper around copy, that sometimes does not copy @@ -389,14 +407,18 @@ sub baseurl sub parse_url { - my ($class, $_) = @_; + &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 (my ($host, $path) = m/^\/\/(.*?)(\/.*)$/) { - - my $o = $class->SUPER::parse_url($path); - $o->{host} = $host; - return $o; + if ($$r =~ m/^\/\/(.*?)(\/.*)$/) { + my $host = $1; + $$r = $2; + return $class->parse_local_url($r, $host); } else { return undef; } diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm index e25254b164e..c26458a5def 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.17 2010/01/09 10:44:42 espie Exp $ +# $OpenBSD: Installed.pm,v 1.18 2010/01/09 11:26:58 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -26,34 +26,6 @@ use warnings; package OpenBSD::PackageRepositoryBase; -sub parse_url -{ - my ($class, $path) = @_; - $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 b9bd790c438..ef4696fe818 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.128 2010/01/09 10:45:32 espie Exp $ +# $OpenBSD: Update.pm,v 1.129 2010/01/09 11:26:58 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); diff --git a/usr.sbin/pkg_add/pkg_info b/usr.sbin/pkg_add/pkg_info index 9758048ac59..2dc5b972b39 100644 --- a/usr.sbin/pkg_add/pkg_info +++ b/usr.sbin/pkg_add/pkg_info @@ -1,6 +1,6 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_info,v 1.86 2010/01/09 10:45:32 espie Exp $ +# $OpenBSD: pkg_info,v 1.87 2010/01/09 11:26:58 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -106,7 +106,7 @@ sub find_pkg my ($repo, $path); - if ($pkgname =~ m/[\/\:]/o) { + if ($pkgname =~ m/\//o) { ($repo, $path, $pkgname) = OpenBSD::PackageLocator::path_parse($pkgname); } else { |