diff options
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepository.pm | 50 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm | 34 |
2 files changed, 52 insertions, 32 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm index e8f289a376a..e661fe6835f 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.32 2007/05/14 12:18:49 espie Exp $ +# $OpenBSD: PackageRepository.pm,v 1.33 2007/05/14 12:49:27 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -474,6 +474,54 @@ sub _new bless { baseurl => $baseurl, key => $distant_host }, $class; } +sub should_have +{ + my ($self, $pkgname) = @_; + if (defined $self->{lasterror} && $self->{lasterror} == 421) { + return (defined $self->{list}) && + grep { $_ eq $pkgname } @{$self->{list}}; + } else { + return 0; + } +} + +sub try_until_success +{ + my ($self, $pkgname, $code) = @_; + + for (my $retry = 5; $retry < 60; $retry *= 2) { + undef $self->{lasterror}; + my $o = &$code; + if (defined $o) { + return $o; + } + if ($self->should_have($pkgname)) { + print STDERR "Temporary error, sleeping $retry seconds\n"; + sleep($retry); + } + } + return undef; +} + +sub find +{ + my ($self, $pkgname, @extra) = @_; + + return $self->try_until_success($pkgname, + sub { + return $self->SUPER::find($pkgname, @extra); }); + +} + +sub grabPlist +{ + my ($self, $pkgname, @extra) = @_; + + return $self->try_until_success($pkgname, + sub { + return $self->SUPER::grabPlist($pkgname, @extra); }); +} + sub parse_problems { my ($self, $filename, $hint) = @_; diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm index fc1cb148339..32b8fa03d9d 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.12 2007/05/14 09:49:27 espie Exp $ +# $OpenBSD: PackageRepositoryList.pm,v 1.13 2007/05/14 12:49:27 espie Exp $ # # Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org> # @@ -40,21 +40,7 @@ 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; - } - } + my $pkg = $repo->find($pkgname, $arch, $srcpath); return $pkg if defined $pkg; } return; @@ -65,21 +51,7 @@ 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; - } - } + my $plist = $repo->grabPlist($pkgname, $arch, $code); return $plist if defined $plist; } return; |