aboutsummaryrefslogtreecommitdiff
path: root/SBO-Lib/lib/SBO/Lib/Download.pm
diff options
context:
space:
mode:
Diffstat (limited to 'SBO-Lib/lib/SBO/Lib/Download.pm')
-rw-r--r--SBO-Lib/lib/SBO/Lib/Download.pm52
1 files changed, 31 insertions, 21 deletions
diff --git a/SBO-Lib/lib/SBO/Lib/Download.pm b/SBO-Lib/lib/SBO/Lib/Download.pm
index e574580..331949b 100644
--- a/SBO-Lib/lib/SBO/Lib/Download.pm
+++ b/SBO-Lib/lib/SBO/Lib/Download.pm
@@ -6,7 +6,7 @@ use warnings;
our $VERSION = '2.8.0';
-use SBO::Lib::Util qw/ :const script_error get_sbo_from_loc open_read get_arch /;
+use SBO::Lib::Util qw/ :const %config script_error get_sbo_from_loc open_read get_arch /;
use SBO::Lib::Repo qw/ $distfiles /;
use SBO::Lib::Info qw/ get_download_info /;
@@ -153,34 +153,44 @@ second value is true, the first one will have an error message.
sub get_distfile {
script_error('get_distfile requires two arguments') unless @_ == 2;
my ($link, $info_md5) = @_;
+
my $filename = get_filename_from_link($link);
mkdir $distfiles unless -d $distfiles;
chdir $distfiles;
- unlink $filename if -f $filename;
+
+ my @links = $link;
my $fail = {};
- # if wget $link && verify, return
- # else wget sbosrcarch && verify
- if (system('wget', '--no-check-certificate', '--tries=5', $link) != 0) {
- $fail->{msg} = "Unable to wget $link.\n";
- $fail->{err} = _ERR_DOWNLOAD;
- }
- return 1 if not %$fail and verify_distfile(@_);
- if (not %$fail) {
- $fail->{msg} = "md5sum failure for $filename.\n";
- $fail->{err} = _ERR_MD5SUM;
+ if ($config{FALLBACK_ARCHIVE} ne 'FALSE') {
+ push(@links, sprintf(
+ "%s/by-md5/%s/%s/%s/%s",
+ $config{FALLBACK_ARCHIVE},
+ substr($info_md5, 0, 1), substr($info_md5, 1, 1), $info_md5, _get_fname($link),
+ ));
}
- # since the download from the original link either didn't download or
- # didn't verify, try to get it from sbosrcarch instead
- unlink $filename if -f $filename;
- my $sbosrcarch = sprintf(
- "ftp://slackware.uk/sbosrcarch/by-md5/%s/%s/%s/%s",
- substr($info_md5, 0, 1), substr($info_md5, 1, 1), $info_md5, _get_fname($link));
+ for my $link (@links) {
+ unlink $filename if -f $filename;
+
+ if (system('wget', '--no-check-certificate', '--tries=5', $link) != 0) {
+ if (not %$fail) {
+ # The failure from the first source is apparently what is important.
+ $fail = {msg => "Unable to wget $link.\n", err => _ERR_DOWNLOAD};
+ }
+
+ next;
+ }
+
+ if (not verify_distfile(@_)) {
+ if (not %$fail) {
+ $fail = {msg => "md5sum failure for $filename.\n", err => _ERR_MD5SUM};
+ }
- return 1 if
- system('wget', '--no-check-certificate', '--tries=5', $sbosrcarch) == 0 and
- verify_distfile(@_);
+ next;
+ }
+
+ return 1;
+ }
return $fail->{msg}, $fail->{err};
}