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 <oreo6391@gmail.com>
This commit is contained in:
Daniel Martinez
2024-05-28 15:31:49 -04:00
committed by oreo639
parent 8738c56ceb
commit c5a5aac026
2 changed files with 16 additions and 9 deletions

View File

@@ -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