summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2010-01-09 13:43:15 +0000
committerMarc Espie <espie@cvs.openbsd.org>2010-01-09 13:43:15 +0000
commitf4adf7ad90fe735dde2faae79d3c45b9c632a04e (patch)
treea98d88015087f1ab6ed3444bc75185d9f601ebaf /usr.sbin/pkg_add
parent1302aec079707d28d0a9ae45d01a5b5f7b1784e4 (diff)
slightly more complex repolist, to allow for:
- caching locations - avoid readding known paths (done thx to unique repo objects)
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm44
1 files changed, 22 insertions, 22 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
index db2292eefcd..97a5f9f09e4 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageRepositoryList.pm,v 1.19 2010/01/09 09:45:40 espie Exp $
+# $OpenBSD: PackageRepositoryList.pm,v 1.20 2010/01/09 13:43:14 espie Exp $
#
# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
#
@@ -23,48 +23,48 @@ package OpenBSD::PackageRepositoryList;
sub new
{
my $class = shift;
- return bless [], $class;
+ return bless {l => [], c => {}, k => {}}, $class;
}
sub add
{
my $self = shift;
- push @$self, @_;
+ for my $r (@_) {
+ next if $self->{k}{$r};
+ push @{$self->{l}}, $r;
+ }
}
-sub find
+sub do_something
{
- my ($self, $pkgname, $arch) = @_;
-
+ my ($self, $do, $pkgname, @args) = @_;
if ($pkgname eq '-') {
- return OpenBSD::PackageRepository::Local::Pipe->new->find($pkgname, $arch);
+ return OpenBSD::PackageRepository::Local::Pipe->new->$do($pkgname, @args);
}
- for my $repo (@$self) {
- my $pkg = $repo->find($pkgname, $arch);
- return $pkg if defined $pkg;
+ for my $repo (@{$self->{l}}) {
+ my $r = $repo->$do($pkgname, @args);
+ return $r if defined $r;
}
- return;
+ return undef;
}
-sub grabPlist
+sub find
{
- my ($self, $pkgname, $arch, $code) = @_;
+ my ($self, @args) = @_;
- if ($pkgname eq '-') {
- return OpenBSD::PackageRepository::Local::Pipe->new->grabPlist($pkgname, $arch, $code);
- }
+ return $self->do_something('find', @args);
+}
- for my $repo (@$self) {
- my $plist = $repo->grabPlist($pkgname, $arch, $code);
- return $plist if defined $plist;
- }
- return;
+sub grabPlist
+{
+ my ($self, @args) = @_;
+ return $self->do_something('grabPlist', @args);
}
sub match_locations
{
my ($self, @search) = @_;
- for my $repo (@$self) {
+ for my $repo (@{$self->{l}}) {
my $l = $repo->match_locations(@search);
if (@$l > 0) {
return $l;