summaryrefslogtreecommitdiff
path: root/include/lib.sh
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2024-07-17 18:15:52 +0100
committerLeah Rowe <leah@libreboot.org>2024-07-17 18:15:52 +0100
commita9f9de885c07541934ecad56ea6c7126f05a89be (patch)
treee29c1c8ba95c3a9aad32cdcc5654faf89777c965 /include/lib.sh
parentef867ecccad5464690c4fa342946fa2c7a4eac3d (diff)
unified cache file handling for vendorfile/subfile
lib.sh download() is used by subfile handling in git.sh, e.g. crossgcc tarballs, and also the vendor scripts. vendor files are cached, but not subfiles for repos. cache both, under cache/file/, saved with the name equal to the checksum, so: cache/file/CHECKSUM also move vendorfiles/app/ to cache/app/ in this change. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include/lib.sh')
-rw-r--r--include/lib.sh19
1 files changed, 10 insertions, 9 deletions
diff --git a/include/lib.sh b/include/lib.sh
index 2fb97c44..791ab4e1 100644
--- a/include/lib.sh
+++ b/include/lib.sh
@@ -180,18 +180,19 @@ singletree()
download()
{
- dl_fail="y" # 1 url, 2 url backup, 3 destination, 4 checksum
- vendor_checksum "$4" "$3" 2>/dev/null || dl_fail="n"
+ cached="cache/file/$4"
+ dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum
+ vendor_checksum "$4" "$cached" 2>/dev/null && dl_fail="y"
[ "$dl_fail" = "n" ] && e "$3" f && return 0
- x_ mkdir -p "${3%/*}" && for url in "$1" "$2"; do
+ x_ mkdir -p "${3%/*}" cache/file && for url in "$1" "$2"; do
[ "$dl_fail" = "n" ] && break
[ -z "$url" ] && continue
- x_ rm -f "$3"
- curl --location --retry 3 -A "$_ua" "$url" -o "$3" || \
- wget --tries 3 -U "$_ua" "$url" -O "$3" || continue
- vendor_checksum "$4" "$3" || dl_fail="n"
- done;
- [ "$dl_fail" = "y" ] && $err "$1 $2 $3 $4: not downloaded"; return 0
+ x_ rm -f "$cached"
+ curl --location --retry 3 -A "$_ua" "$url" -o "$cached" || \
+ wget --tries 3 -U "$_ua" "$url" -O "$cached" || continue
+ vendor_checksum "$4" "$cached" || dl_fail="n"
+ done; [ "$dl_fail" = "y" ] && $err "$1 $2 $3 $4: not downloaded"
+ [ "$cached" = "$3" ] || cp "$cached" "$3" || $err "!d cp $cached $3"; :
}
vendor_checksum()