summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2006-03-04 13:13:06 +0000
committerMarc Espie <espie@cvs.openbsd.org>2006-03-04 13:13:06 +0000
commit2671c587bc640f9caf86a61f5d0a8a8cca0eb5ca (patch)
tree90d97a87055042fa85bcae27bbf04bace8edbca4 /usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
parent54f12c977cbe82c0a95b797c6c9971492a8e3df7 (diff)
cut down the Locator code into maintainable chunks.
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm104
1 files changed, 104 insertions, 0 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
new file mode 100644
index 00000000000..c6868ac4099
--- /dev/null
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
@@ -0,0 +1,104 @@
+# ex:ts=8 sw=4:
+# $OpenBSD: PackageRepositoryList.pm,v 1.1 2006/03/04 13:13:05 espie Exp $
+#
+# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+use strict;
+use warnings;
+
+package OpenBSD::PackageRepositoryList;
+
+sub new
+{
+ my $class = shift;
+ return bless {list => [], avail => undef }, $class;
+}
+
+sub add
+{
+ my $self = shift;
+ push @{$self->{list}}, @_;
+ if (@_ > 0) {
+ $self->{avail} = undef;
+ }
+}
+
+sub find
+{
+ my ($self, $pkgname, $arch, $srcpath) = @_;
+
+ for my $repo (@{$self->{list}}) {
+ my $pkg;
+
+ for (my $retry = 5; $retry < 60; $retry *= 2) {
+ undef $repo->{lasterror};
+ $pkg = $repo->find($pkgname, $arch, $srcpath);
+ if (!defined $pkg && defined $repo->{lasterror} &&
+ $repo->{lasterror} == 421 &&
+ defined $self->{avail} &&
+ $self->{avail}->{$pkgname} eq $repo) {
+ print STDERR "Temporary error, sleeping $retry seconds\n";
+ sleep($retry);
+ } else {
+ last;
+ }
+ }
+ return $pkg if defined $pkg;
+ }
+ return undef;
+}
+
+sub grabPlist
+{
+ my ($self, $pkgname, $arch, $code) = @_;
+
+ for my $repo (@{$self->{list}}) {
+ my $plist;
+
+ for (my $retry = 5; $retry < 60; $retry *= 2) {
+ undef $repo->{lasterror};
+ $plist = $repo->grabPlist($pkgname, $arch, $code);
+ if (!defined $plist && defined $repo->{lasterror} &&
+ $repo->{lasterror} == 421 &&
+ defined $self->{avail} &&
+ $self->{avail}->{$pkgname} eq $repo) {
+ print STDERR "Temporary error, sleeping $retry seconds\n";
+ sleep($retry);
+ } else {
+ last;
+ }
+ }
+ return $plist if defined $plist;
+ }
+ return undef;
+}
+
+sub available
+{
+ my $self = shift;
+
+ if (!defined $self->{avail}) {
+ my $available_packages = {};
+ foreach my $loc (reverse @{$self->{list}}) {
+ foreach my $pkg (@{$loc->list()}) {
+ $available_packages->{$pkg} = $loc;
+ }
+ }
+ $self->{avail} = $available_packages;
+ }
+ return keys %{$self->{avail}};
+}
+
+1;