diff options
-rw-r--r-- | ChangeLog.md | 7 | ||||
-rw-r--r-- | SBO-Lib/lib/SBO/Lib/Download.pm | 52 | ||||
-rw-r--r-- | SBO-Lib/lib/SBO/Lib/Util.pm | 1 | ||||
-rw-r--r-- | completions/zsh/_sboconfig | 1 | ||||
-rw-r--r-- | etc/sbotools.conf | 3 | ||||
-rw-r--r-- | man1/sboconfig.1 | 5 | ||||
-rw-r--r-- | man5/sbotools.conf.5 | 5 | ||||
-rwxr-xr-x | sboconfig | 22 | ||||
-rwxr-xr-x | t/15-usage.t | 2 |
9 files changed, 74 insertions, 24 deletions
diff --git a/ChangeLog.md b/ChangeLog.md index ba7fe16..61481ba 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## [Unreleased] + +### Added + + - Download's are retried from a third party on failure. Allow the user to + configure the third party source or disable this feature. + ## [2.8.0] - 2025-01-28 ### Added 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}; } diff --git a/SBO-Lib/lib/SBO/Lib/Util.pm b/SBO-Lib/lib/SBO/Lib/Util.pm index 1598cf1..83e837b 100644 --- a/SBO-Lib/lib/SBO/Lib/Util.pm +++ b/SBO-Lib/lib/SBO/Lib/Util.pm @@ -115,6 +115,7 @@ our %config = ( SLACKWARE_VERSION => 'FALSE', REPO => 'FALSE', GPG_KEY => 'D3076BC3E783EE747F09B8B70368EF579C7BA3B6', + FALLBACK_ARCHIVE => "ftp://slackware.uk/sbosrcarch", ); read_config(); diff --git a/completions/zsh/_sboconfig b/completions/zsh/_sboconfig index 69e2984..36d27ff 100644 --- a/completions/zsh/_sboconfig +++ b/completions/zsh/_sboconfig @@ -10,6 +10,7 @@ _arguments \ - commands \ '(-c --noclean)'{-c,--noclean}'[If TRUE, then do not clean working directories after build.]:clean work dirs?:((TRUE\:"Clean works directories" FALSE\:"Keep work directories"))' \ '(-d --distclean)'{-d,--distclean}'[If TRUE, then remove source code after building.]:clean source?:((TRUE\:"Remove source" FALSE\:"Keep source"))' \ + '(-f --fallback-archive)'{-f,--fallback-archive}'[Fallback URL to download package sources. FALSE to disable.]:use fallback achive?:((FALSE\:"Disable"))' \ '(-g --gpg-key)'{-g,--gpg-key}'[The gpg key used for verification, FALSE to disable.]:use gpg?:((FALSE\:"Do not verify"))' \ '(-j --jobs)'{-j,--jobs}'[Number fed to -j# for make.]:number of jobs (make):()' \ '(-p --pkg-dir)'{-p,--pkg-dir}'[Directory to store built packages in.]:package directory:_files -/' \ diff --git a/etc/sbotools.conf b/etc/sbotools.conf index ecede5c..8f7d430 100644 --- a/etc/sbotools.conf +++ b/etc/sbotools.conf @@ -4,6 +4,9 @@ # DISTCLEAN can be FALSE or TRUE. # DISTCLEAN=TRUE +# FALLBACK_SOURCE_ARCHIVE can be FALSE or a URL. +# FALLBACK_ARCHIVE=ftp://slackware.uk/sbosrcarch + # JOBS can be FALSE or a number. # JOBS=FALSE diff --git a/man1/sboconfig.1 b/man1/sboconfig.1 index e8c9a35..ef32cd2 100644 --- a/man1/sboconfig.1 +++ b/man1/sboconfig.1 @@ -35,6 +35,11 @@ NOCLEAN: If TRUE, then DO NOT clean working directories after building the slack DISTCLEAN: If TRUE, then DO remove the source code after building the slackbuild. By default, the source code is not removed, and lives under $SBO_HOME/distfiles, which, by default, is /usr/sbo/distfiles. Setting this option to TRUE causes the source code to be removed by default. This can be overridden when running sboupgrade(1)/sboinstall(1). .RE .P +-f|--fallback-archive (FALSE|url) +.RS +FALLBACK_ARCHIVE: If set to a url, use that url as a fallback to attempt downloading from when the original URL fails. +.RE +.P -j|--jobs (FALSE|#) .RS JOBS: If numeric (2,5,10, etc), then that number will be fed to the "-j" argument to make when a slackbuild which invokes "make" is run. This only makes sense on multicore systems, where one might set the JOBS to the number of available cores, or half that number, etc. diff --git a/man5/sbotools.conf.5 b/man5/sbotools.conf.5 index 44765cb..d76c11a 100644 --- a/man5/sbotools.conf.5 +++ b/man5/sbotools.conf.5 @@ -13,6 +13,11 @@ DISTCLEAN=(FALSE|TRUE) If TRUE, then DO remove the source code after building the slackbuild. By default, the source code is not removed, and lives under $SBO_HOME/distfiles, which, by default, is /usr/sbo/distfiles. Setting this option to TRUE causes the source code to be removed by default. This can be overridden when running sboupgrade(1)/sboinstall(1). .RE .P +FALLBACK_ARCHIVE=(FALSE|url) +.RS +If set to a url, use that url as a fallback to attempt downloading from when the original URL fails. +.RE +.P JOBS=(FALSE|#) .RS If numeric (2,5,10, etc), then that number will be fed to the "-j" argument to make when a SlackBuild which invokes "make" is run. This only makes sense on multicore systems, where one might set the JOBS to the number of available cores, or half that number, etc. @@ -39,6 +39,8 @@ Config options (defaults shown): NOCLEAN: if TRUE, do NOT clean up after building by default. -d|--distclean FALSE: DISTCLEAN: if TRUE, DO clean distfiles by default after building. + -f|--fallback-archive ftp://slackware.uk/sbosrcarch: + FALLBACK_ARCHIVE: Fallback URL to download package source's. FALSE to disable. -j|--jobs FALSE: JOBS: numeric -j setting to feed to make for multicore systems. -g|--gpg-key D3076BC3E783EE747F09B8B70368EF579C7BA3B6: @@ -60,9 +62,21 @@ EOF my %options; -GetOptions(\%options, 'help|h', 'version|v', 'list|l', 'noclean|c=s', - 'distclean|d=s', 'jobs|j=s', 'pkg-dir|p=s', 'sbo-home|s=s', - 'local-overrides|o=s', 'slackware-version|V=s', 'repo|r=s', 'gpg-key|g=s'); +GetOptions(\%options, + 'help|h', + 'version|v', + 'list|l', + 'noclean|c=s', + 'fallback-archive|f=s', + 'distclean|d=s', + 'jobs|j=s', + 'pkg-dir|p=s', + 'sbo-home|s=s', + 'local-overrides|o=s', + 'slackware-version|V=s', + 'repo|r=s', + 'gpg-key|g=s', +); if ($options{help}) { show_usage(); exit 0 } if ($options{version}) { show_version(); exit 0 } @@ -70,6 +84,7 @@ if ($options{version}) { show_version(); exit 0 } my %valid_confs = ( noclean => 'NOCLEAN', distclean => 'DISTCLEAN', + 'fallback-archive' => 'FALLBACK_ARCHIVE', jobs => 'JOBS', 'gpg-key' => 'GPG_KEY', 'pkg-dir' => 'PKG_DIR', @@ -82,6 +97,7 @@ my %valid_confs = ( my %params = ( NOCLEAN => 'c|--noclean', DISTCLEAN => 'd|--distclean', + FALLBACK_ARCHIVE => 'f|--fallback-archive', JOBS => 'j|--jobs', GPG_KEY => 'g|--gpg-key', PKG_DIR => 'p|--pkg-dir', diff --git a/t/15-usage.t b/t/15-usage.t index c528444..c30acab 100755 --- a/t/15-usage.t +++ b/t/15-usage.t @@ -62,6 +62,8 @@ Config options (defaults shown): NOCLEAN: if TRUE, do NOT clean up after building by default. -d|--distclean FALSE: DISTCLEAN: if TRUE, DO clean distfiles by default after building. + -f|--fallback-archive ftp://slackware.uk/sbosrcarch:
+ FALLBACK_ARCHIVE: Fallback URL to download package source's. FALSE to disable.
-j|--jobs FALSE: JOBS: numeric -j setting to feed to make for multicore systems. -g|--gpg-key D3076BC3E783EE747F09B8B70368EF579C7BA3B6: |