build: make GitHub archive fallback resumable

Download archive into .part, validate with gzip -t, retry, then extract. Helps on flaky TLS connections.
This commit is contained in:
OrangePi CM5 Builder 2026-04-09 21:23:10 +08:00
parent f84cd6a168
commit 2a0e5c9f07
1 changed files with 22 additions and 2 deletions

View File

@ -365,12 +365,32 @@ fetch_from_github_archive()
local tar_url="${base}/archive/refs/heads/${ref_name}.tar.gz"
local archive_dir="${EXTER}/cache/sources/.github-archives"
local tar_path="${archive_dir}/$(basename "${base}")-${ref_name}.tar.gz"
local tar_part="${tar_path}.part"
mkdir -p "${archive_dir}" || return 1
display_alert "Downloading GitHub archive" "${tar_url}" "wrn"
# -c enables resume; keep a cached tarball in EXTER/cache/sources
wget -q -c -t 10 --timeout=30 --waitretry=5 -O "${tar_path}" "${tar_url}" || return 1
local attempt
for attempt in 1 2 3; do
# Resume into a .part file, verify integrity, then promote.
if command -v curl >/dev/null 2>&1; then
curl -L --fail --retry 10 --retry-delay 5 --connect-timeout 30 \
--continue-at - -o "${tar_part}" "${tar_url}" || true
else
wget -c -t 10 --timeout=30 --waitretry=5 -O "${tar_part}" "${tar_url}" || true
fi
if gzip -t "${tar_part}" >/dev/null 2>&1; then
mv -f "${tar_part}" "${tar_path}" || return 1
break
fi
display_alert "Archive download incomplete; retrying" "attempt ${attempt}/3" "wrn"
rm -f "${tar_part}" 2>/dev/null || true
sleep 5
done
[[ -f "${tar_path}" ]] || return 1
display_alert "Extracting archive" "${workdir}" "wrn"
mkdir -p "${workdir}" || return 1