From c5a5aac026689abfd2b03152e82d759a401fb306 Mon Sep 17 00:00:00 2001 From: Daniel Martinez Date: Tue, 28 May 2024 15:31:49 -0400 Subject: [PATCH] xbps-src: add option to use distfiles mirror as a fallback This adds an optional configuration to add a fallback distfiles mirror The idea is that normally, distfiles should be fetched from the urls in the template. However, occasionally the urls have rotted, or are simply down temporairily, in which case the fetch will fail. A workaround to this has been to use the $XBPS_DISTFILES_MIRROR option, however the downside to this is that it is always tried first, and 99% of the time isn't needed. This adds the $XBPS_DISTFILES_FALLBACK option, which can be set to an addiontional list of mirrors which will be attempted after both $XBPS_DISTFILES_MIRROR, and the urls in the template have failed to fetch the distfiles Co-authored-by: oreo639 --- common/hooks/do-fetch/00-distfiles.sh | 15 +++++++++------ xbps-src | 10 +++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/common/hooks/do-fetch/00-distfiles.sh b/common/hooks/do-fetch/00-distfiles.sh index 1adb86a5167..2065d5442a3 100644 --- a/common/hooks/do-fetch/00-distfiles.sh +++ b/common/hooks/do-fetch/00-distfiles.sh @@ -128,11 +128,11 @@ link_cksum() { } try_mirrors() { - local curfile="$1" distfile="$2" cksum="$3" f="$4" + local curfile="$1" distfile="$2" cksum="$3" f="$4" mirror_list="$5" local filesum basefile mirror path scheme good - [ -z "$XBPS_DISTFILES_MIRROR" ] && return 1 + [ -z "$mirror_list" ] && return 1 basefile="${f##*/}" - for mirror in $XBPS_DISTFILES_MIRROR; do + for mirror in $mirror_list; do scheme="file" if [[ $mirror == *://* ]]; then scheme="${mirror%%:/*}" @@ -148,8 +148,8 @@ try_mirrors() { continue fi fi - if [[ "$mirror" == *voidlinux* ]]; then - # For distfiles.voidlinux.* append the subdirectory + if [[ "$mirror" == *sources.voidlinux.* ]]; then + # For sources.voidlinux.* append the subdirectory mirror="$mirror/$pkgname-$version" fi msg_normal "$pkgver: fetching distfile '$curfile' from mirror '$mirror'...\n" @@ -286,11 +286,14 @@ hook() { fi # If distfile does not exist, download it from a mirror location. - if try_mirrors "$curfile" "$distfile" "${_checksums[$i]}" "${_distfiles[$i]}"; then + if try_mirrors "$curfile" "$distfile" "${_checksums[$i]}" "${_distfiles[$i]}" "$XBPS_DISTFILES_MIRROR"; then continue fi if ! try_urls "$curfile"; then + if try_mirrors "$curfile" "$distfile" "${_checksums[$i]}" "${_distfiles[$i]}" "$XBPS_DISTFILES_FALLBACK"; then + continue + fi msg_error "$pkgver: failed to fetch '$curfile'.\n" fi done diff --git a/xbps-src b/xbps-src index c17270b62ee..1ce830c7bf9 100755 --- a/xbps-src +++ b/xbps-src @@ -343,10 +343,11 @@ read_pkg() { } setup_distfiles_mirror() { + local mirror_list="$1" local mirror scheme path # Scheme file:// mirror locations only work with uchroot - for mirror in $XBPS_DISTFILES_MIRROR; do + for mirror in $mirror_list; do scheme="file" if [[ "$mirror" == *://* ]]; then scheme="${mirror%%://*}" @@ -696,7 +697,7 @@ export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \ XBPS_LIBEXECDIR XBPS_DISTDIR XBPS_DISTFILES_MIRROR XBPS_ALLOW_RESTRICTED \ XBPS_USE_GIT_COMMIT_DATE XBPS_PKG_COMPTYPE XBPS_REPO_COMPTYPE \ XBPS_BUILDHELPERDIR XBPS_USE_BUILD_MTIME XBPS_BUILD_ENVIRONMENT \ - XBPS_PRESERVE_PKGS XBPS_IGNORE_BROKENNESS + XBPS_PRESERVE_PKGS XBPS_IGNORE_BROKENNESS XBPS_DISTFILES_FALLBACK for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do eval val="\$XBPS_$i" @@ -760,7 +761,10 @@ done if [ -z "$IN_CHROOT" ]; then trap 'exit_func' INT TERM if [ -n "$XBPS_DISTFILES_MIRROR" ]; then - setup_distfiles_mirror + setup_distfiles_mirror "$XBPS_DISTFILES_MIRROR" + fi + if [ -n "$XBPS_DISTFILES_FALLBACK" ]; then + setup_distfiles_mirror "$XBPS_DISTFILES_FALLBACK" fi fi