summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2025-05-14 16:28:29 +0100
committerLeah Rowe <leah@libreboot.org>2025-05-14 16:28:29 +0100
commite9fe5a74a2e66906721fe2ca1beb1f14784cf675 (patch)
tree5b1b1300c416907c85220e4e68f2743ea382a41a
parent6089716f07caf6b4690df1e1c2f2089a27a0b514 (diff)
get.sh: fix caching of crossgcc tarballs
they were always re-downloading every time. i've basically re-written most of xbmkget. there was some erroneous conditions under which it wrongly deleted the cached file, resulting in it being downloaded again. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--include/get.sh44
-rw-r--r--include/vendor.sh2
2 files changed, 24 insertions, 22 deletions
diff --git a/include/get.sh b/include/get.sh
index 9405828e..fbb41cd3 100644
--- a/include/get.sh
+++ b/include/get.sh
@@ -53,7 +53,7 @@ git_prep()
_loc="$4" # $1 and $2 are gitrepo and gitrepo_backup
chkvars rev
- xbmkget "$1" "$2" "$tmpgit" "$rev" git "$_patchdir"
+ xbmkget git "$1" "$2" "$tmpgit" "$rev" "$_patchdir"
if singletree "$project" || [ $# -gt 4 ]; then
dx_ fetch_submodule "$mdir/module.list"
fi
@@ -78,46 +78,46 @@ fetch_submodule()
[ -z "$st" ] && return 0 # subrepo/subfile not defined
chkvars "sub${st}" "sub${st}_bkup" "subhash"
- [ "$st" = "file" ] && xbmkget "$subfile" "$subfile_bkup" \
+ [ "$st" = "file" ] && xbmkget curl "$subfile" "$subfile_bkup" \
"$tmpgit/$1" "$subhash" && return 0
x_ rm -Rf "$tmpgit/$1"
- xbmkget "$subrepo" "$subrepo_bkup" "$tmpgit/$1" "$subhash" git \
+ xbmkget git "$subrepo" "$subrepo_bkup" "$tmpgit/$1" "$subhash" \
"$mdir/${1##*/}/patches"
}
-# can grab from the internet, or copy locally.
-# if copying locally, it can only copy a file.
xbmkget()
{
- _dlop="curl" && [ $# -gt 4 ] && _dlop="$5"
- [ "$_dlop" = "curl" ] || [ "$_dlop" = "copy" ] || \
- [ "$_dlop" = "git" ] || err "$1 $2 $3 $4: Bad dlop type: '$_dlop'"
+ [ "$1" = "curl" ] || [ "$1" = "copy" ] || [ "$1" = "git" ] || \
+ err "Bad dlop (arg 1): xbmkget $*"
- for url in "$1" "$2"; do
- [ -n "$url" ] && try_file "$url" "$_dlop" "$@" && return 0
+ for url in "$2" "$3"; do
+ [ -n "$url" ] && try_file "$url" "$@" && return 0
done && err "$1 $2 $3 $4: not downloaded"; :
}
try_file()
{
cached="file/$6" && [ "$2" = "git" ] && cached="clone/${3##*/}" && \
- cached="${cached%.git}"
+ cached="${cached%.git}" # always the main repo as basis for naming,
+ # in case the backup has another name
cached="$XBMK_CACHE/$cached"
x_ mkdir -p "${5%/*}" "${cached%/*}"
- echk="d" && dl_fail="n" && [ "$2" != "git" ] && echk="f" && \
- bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y"
- [ "$dl_fail" = "n" ] && e "$5" $echk && return 0
+ echk="d" && [ "$2" != "git" ] && echk="f" && \
+ bad_checksum "$6" "$cached" 2>/dev/null && x_ rm -f "$cached"
- [ "$2" != "git" ] && x_ rm -f "$cached"
-
- try_$2 "$cached" "$@" || return 1
+ e "$cached" $echk || try_$2 "$cached" "$@" || return 1
+ if e "$5" $echk && [ "$2" != "git" ]; then
+ bad_checksum "$6" "$5" 2>/dev/null && x_ cp "$cached" "$5"
+ fi
+ e "$cached" $echk missing && return 1
if [ "$2" = "git" ]; then
- tmpclone "$cached" "$5" "$6" "$8" || return 1
+ tmpclone "$cached" "$5" "$6" "$7" || return 1
else
- bad_checksum "$6" "$cached" && return 1
+ bad_checksum "$6" "$cached" && x_ rm -f "$cached" && return 1
[ "$cached" != "$5" ] && x_ cp "$cached" "$5"
+ bad_checksum "$6" "$5" && x_ rm -rf "$5" && return 1; :
fi
}
@@ -154,8 +154,10 @@ try_git()
bad_checksum()
{
- [ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1
- printf "Bad checksum for file: %s\n" "$2" 1>&2; rm -f "$2" || :; :
+ [ ! -f "$2" ] || [ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] \
+ || return 1
+ printf "Bad checksum for file: %s\n" "$2" 1>&2
+ x_ rm -f "$2"
}
tmpclone()
diff --git a/include/vendor.sh b/include/vendor.sh
index fb49cca5..823ba74f 100644
--- a/include/vendor.sh
+++ b/include/vendor.sh
@@ -90,7 +90,7 @@ fetch()
done; :
dlop="curl" && [ $# -gt 5 ] && dlop="$6"
- xbmkget "$dl" "$dl_bkup" "$_dl" "$dlsum" "$dlop"
+ xbmkget "$dlop" "$dl" "$dl_bkup" "$_dl" "$dlsum"
x_ rm -Rf "${_dl}_extracted"
e "$_dest" f && return 0