summaryrefslogtreecommitdiff
path: root/Master/tlpkg/TeXLive/TLDownload.pm
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2010-06-05 16:31:31 +0000
committerNorbert Preining <preining@logic.at>2010-06-05 16:31:31 +0000
commitaec43c7830a63c5cc82c699f4490862af0d91958 (patch)
tree585e905c2b287f9f517a516e26859391d3937427 /Master/tlpkg/TeXLive/TLDownload.pm
parentd65aa576328f6698d7e7bf7c65119281cbca0981 (diff)
various changes:
- install-tl: try to add /systems/texlive/tlnet if initial download does not succeed - TLDownload errorcount/enable/disable support (used in install-tl) - TLUtils: check for TLDownload enabled status - TLPDB: remove warning about unsuccessfull download of .tlpdb, it is now in tlmgr (where it was already) and install-tl. git-svn-id: svn://tug.org/texlive/trunk@18756 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/TeXLive/TLDownload.pm')
-rw-r--r--Master/tlpkg/TeXLive/TLDownload.pm79
1 files changed, 79 insertions, 0 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