diff options
Diffstat (limited to 'Master/tlpkg')
-rw-r--r-- | Master/tlpkg/TeXLive/TLDownload.pm | 79 | ||||
-rw-r--r-- | Master/tlpkg/TeXLive/TLPDB.pm | 18 | ||||
-rw-r--r-- | Master/tlpkg/TeXLive/TLUtils.pm | 2 |
3 files changed, 82 insertions, 17 deletions
diff --git a/Master/tlpkg/TeXLive/TLDownload.pm b/Master/tlpkg/TeXLive/TLDownload.pm index 1977c2023fe..27370da4855 100644 --- a/Master/tlpkg/TeXLive/TLDownload.pm +++ b/Master/tlpkg/TeXLive/TLDownload.pm @@ -20,6 +20,7 @@ sub module_revision { return $_modulerevision; } +my $MAX_ERRORCOUNT = 5; # since Net::HTTP and Net::FTP are shipped by the same packages # we only test for Net::HTTP, if that fails, let us know ;-) @@ -46,16 +47,73 @@ sub new env_proxy => 1, ); $self->{'ua'} = $ua; + $self->{'enabled'} = 1; + $self->{'errorcount'} = 0; bless $self, $class; return $self; } + +sub enabled +{ + my $self = shift; + return $self{'enabled'}; +} +sub disabled +{ + my $self = shift; + return (!$self{'enabled'}); +} +sub enable +{ + my $self = shift; + $self{'enabled'} = 1; + # also reset the error conter + $self->reset_errorcount; +} +sub disable +{ + my $self = shift; + $self{'enabled'} = 0; +} +sub errorcount +{ + my $self = shift; + if (@_) { $self->{'errorcount'} = shift } + return $self->{'errorcount'}; +} +sub incr_errorcount +{ + my $self = shift; + return(++$self->{'errorcount'}); +} +sub decr_errorcount +{ + my $self = shift; + if ($self->errorcount > 0) { + return(--$self->{'errorcount'}); + } else { + return($self->errorcount(0)); + } +} +sub reset_errorcount +{ + my $self = shift; + $self->{'errorcount'} = 0; +} sub get_file { my ($self, $url, $out, $size) = @_; # + # automatically disable if error count is getting too big + if ($self->errorcount > $MAX_ERRORCOUNT) { + $self->disable; + } + # return if disabled + return if $self->disabled; + # my $realout = $out; my ($outfh, $outfn); if ($out eq "|") { @@ -64,6 +122,7 @@ sub get_file } my $response = $self->{'ua'}->get($url, ':content_file' => $realout); if ($response->is_success) { + $self->decr_errorcount; if ($out ne "|") { return 1; } else { @@ -74,6 +133,7 @@ sub get_file } else { tlwarn("TLDownload::get_file: response error:\n"); tlwarn(" " . $response->status_line . "\n"); + $self->incr_errorcount; return; } } @@ -95,6 +155,14 @@ C<TeXLive::TLDownload> -- TeX Live Download abstraction module $TeXLive::TLDownload::net_lib_avail my $dl = TeXLive::TLDownload->new(); $dl->get_file($relpath, $output [, $expected_size ]); + if ($dl->enabled) ... + if ($dl->disabled) ... + $dl->enable; + $dl->disable; + $dl->errorcount([n]); + $dl->incr_errorcount; + $dl->decr_errorcount; + $dl->reset_errorcount; =head1 DESCRIPTION @@ -108,6 +176,17 @@ C<$TeXLive::TLDownload::net_lib_avail> accordingly. Please see C<LWP::UserAgent> for details, in a nut shell one can specify proxies by setting C<I<protocol>_proxy> variables. +=head2 Automatic disabling + +The TLDownload module implements some automatic disabling feature. +Every time a download did not succeed an internal counter (errorcount) +is increased, everytime it did succeed it is decreased (to a minimum of 0). +If the number of error goes above the maximal error count, the download +object will be disabled and get_file always returns undef. + +In this cases the download can be reset with the reset_errorcount and +enable function. + =head1 SEE ALSO LWP diff --git a/Master/tlpkg/TeXLive/TLPDB.pm b/Master/tlpkg/TeXLive/TLPDB.pm index 8993105264c..2138e4e4179 100644 --- a/Master/tlpkg/TeXLive/TLPDB.pm +++ b/Master/tlpkg/TeXLive/TLPDB.pm @@ -293,22 +293,8 @@ sub from_file { } } until (!$ret); if (! $found) { - tlwarn("$0: Could not load packages from\n"); - tlwarn(" $path\n"); - if ($path =~ m,/2008(/|$),) { - # have to do this differently in 09/10, since the path will be the same. - tlwarn("TeX Live 2008 is no longer available for updates.\n") - } else { - tlwarn(<<END_EXPLICIT_MIRROR); - -You may want to try specifying an explicit or different CTAN mirror; -see the information and examples for the -repository option at -http://tug.org/texlive/doc/install-tl.html -(or in the output of install-tl --help). - -END_EXPLICIT_MIRROR - # above text duplicated in tlmgr.pl, sorry. - } + debug("$0: Could not load packages from\n"); + debug(" $path\n"); } # remove the un-xz-ed tlpdb file from temp dir diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm index 3658689b808..9ec12ace487 100644 --- a/Master/tlpkg/TeXLive/TLUtils.pm +++ b/Master/tlpkg/TeXLive/TLUtils.pm @@ -2243,7 +2243,7 @@ sub download_file { } else { $url = "$TeXLiveURL/$relpath"; } - if (defined($::tldownload_server)) { + if (defined($::tldownload_server) && $::tldownload_server->enabled) { if (($ret = $::tldownload_server->get_file($url, $dest))) { debug("downloading file via permanent connection succeeded\n"); return $ret; |