summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2008-07-04 10:47:14 +0000
committerMarc Espie <espie@cvs.openbsd.org>2008-07-04 10:47:14 +0000
commitb3753a2ee5b621168a705031b4255daedf3be6f3 (patch)
tree0b72b5fa588cc831c604681eb55abad461aa4c12
parentf77f243a8feb8c249af9b216cdd159a45d30cd27 (diff)
clean up parser a bit, separating local/distant parts in a more reusable way,
and simplify file: parsing scheme (trying it with file:, then without is a bit stupid once we have the pieces to put it back together directly). Drop the restriction on urls from the man page, no need to finish stuff with /.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository.pm116
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository/Source.pm8
-rw-r--r--usr.sbin/pkg_add/pkg_add.19
3 files changed, 77 insertions, 56 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
index 819c41e8849..e4ef299c719 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.57 2008/07/03 18:45:51 sturm Exp $
+# $OpenBSD: PackageRepository.pm,v 1.58 2008/07/04 10:47:13 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -41,11 +41,7 @@ sub baseurl
{
my $self = shift;
- if (defined $self->{host}) {
- return "//$self->{host}/$self->{path}";
- } else {
- return $self->{path};
- }
+ return $self->{path};
}
sub new
@@ -55,37 +51,46 @@ sub new
return $o;
}
-sub _parse
+sub strip_urlscheme
{
my ($class, $r) = @_;
if ($$r =~ m/^(.*?)\:(.*)$/) {
my $scheme = lc($1);
- if ($scheme ne $class->urlscheme) {
- return undef;
+ 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;
- my $o;
- # use similar heuristics as ftp
- if ($$r =~ m/^\/\/(.*?)(\/.*)$/) {
- my $host = $1;
- $$r = $2;
- if ($$r =~ m/^(.*?)\:(.*)$/) {
- $o = $class->_new($1, $host);
- $$r = $2;
- } else {
- $o = $class->_new($$r, $host);
- $$r = '';
- }
- } elsif ($$r =~ m/^(.*?)\:(.*)/) { # no /, split on :
- $o = $class->_new($1);
- $$r = $2;
- } else {
- $o = $class->_new($$r);
- $$r = '';
- }
- return $o;
+ } else {
+ $o = $class->_new($$r, @args);
+ $$r = '';
}
- return undef;
+ return $o;
+}
+
+sub parse_url
+{
+ &parse_local_url;
+}
+
+sub parse_fullurl
+{
+ my ($class, $r) = @_;
+
+ $class->strip_urlscheme($r) or return undef;
+ return $class->parse_url($r);
}
sub parse
@@ -95,25 +100,25 @@ sub parse
return undef if $_ eq '';
if (m/^ftp\:/io) {
- return OpenBSD::PackageRepository::FTP->_parse($ref);
+ return OpenBSD::PackageRepository::FTP->parse_fullurl($ref);
} elsif (m/^http\:/io) {
- return OpenBSD::PackageRepository::HTTP->_parse($ref);
+ return OpenBSD::PackageRepository::HTTP->parse_fullurl($ref);
} elsif (m/^https\:/io) {
- return OpenBSD::PackageRepository::HTTPS->_parse($ref);
+ return OpenBSD::PackageRepository::HTTPS->parse_fullurl($ref);
} elsif (m/^scp\:/io) {
require OpenBSD::PackageRepository::SCP;
- return OpenBSD::PackageRepository::SCP->_parse($ref);
+ return OpenBSD::PackageRepository::SCP->parse_fullurl($ref);
} elsif (m/^src\:/io) {
require OpenBSD::PackageRepository::Source;
- return OpenBSD::PackageRepository::Source->_parse($ref);
+ return OpenBSD::PackageRepository::Source->parse_fullurl($ref);
} elsif (m/^file\:/io) {
- return OpenBSD::PackageRepository::Local->_parse($ref);
+ return OpenBSD::PackageRepository::Local->parse_fullurl($ref);
} elsif (m/^inst\:$/io) {
- return OpenBSD::PackageRepository::Installed->_parse($ref);
+ return OpenBSD::PackageRepository::Installed->parse_fullurl($ref);
} else {
- return OpenBSD::PackageRepository::Local->_parse($ref);
+ return OpenBSD::PackageRepository::Local->parse_fullurl($ref);
}
}
@@ -266,13 +271,12 @@ sub urlscheme
return 'file';
}
-sub _parse
+sub parse_fullurl
{
my ($class, $r) = @_;
- my $o = $class->SUPER::_parse($r);
- return $o if defined $o;
- $$r = "file:$$r";
- return $class->SUPER::_parse($r);
+
+ $class->strip_urlscheme($r);
+ return $class->parse_local_url($r);
}
sub open_pipe
@@ -361,6 +365,32 @@ sub open_pipe
package OpenBSD::PackageRepository::Distant;
our @ISA=qw(OpenBSD::PackageRepository);
+sub baseurl
+{
+ my $self = shift;
+
+ return "//$self->{host}/$self->{path}";
+}
+
+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);
+ } else {
+ return undef;
+ }
+}
+
my $buffsize = 2 * 1024 * 1024;
sub pkg_copy
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Source.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Source.pm
index 39e8708a7b9..68a56cbedb0 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Source.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Source.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Source.pm,v 1.7 2007/12/28 12:57:13 espie Exp $
+# $OpenBSD: Source.pm,v 1.8 2008/07/04 10:47:13 espie Exp $
#
# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
#
@@ -28,12 +28,6 @@ sub urlscheme
return 'src';
}
-sub _new
-{
- my ($class, $baseurl) = @_;
- bless { baseurl => $baseurl }, $class;
-}
-
sub build_package
{
my ($self, $pkgpath) = @_;
diff --git a/usr.sbin/pkg_add/pkg_add.1 b/usr.sbin/pkg_add/pkg_add.1
index 7e3d932c7dc..7e3bd9ef30d 100644
--- a/usr.sbin/pkg_add/pkg_add.1
+++ b/usr.sbin/pkg_add/pkg_add.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pkg_add.1,v 1.72 2008/03/09 15:36:45 jmc Exp $
+.\" $OpenBSD: pkg_add.1,v 1.73 2008/07/04 10:47:13 espie Exp $
.\"
.\" Documentation and design originally from FreeBSD. All the code has
.\" been rewritten since. We keep the documentation's notice:
@@ -15,7 +15,7 @@
.\" Jordan K. Hubbard
.\"
.\"
-.Dd $Mdocdate: March 9 2008 $
+.Dd $Mdocdate: July 4 2008 $
.Dt PKG_ADD 1
.Os
.Sh NAME
@@ -102,9 +102,6 @@ If the given package names are not found in the current working directory,
will search for them in each directory named by the
.Ev PKG_PATH
environment variable.
-Since a few URL schemes contain colons,
-.Nm
-relies on each directory ending in a / to split the path correctly.
Specifying
.Ql -
as a package name causes
@@ -594,7 +591,7 @@ the directories named by
.Ev PKG_PATH
are searched.
It should contain a series of entries separated by colons.
-Each entry consists of a directory name, ending in a slash.
+Each entry consists of a directory name.
URL schemes such as FTP, HTTP, HTTPS, or SCP are also appropriate.
The current directory may be indicated
implicitly by an empty directory name, or explicitly by a single