aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-06-24 16:38:45 +0200
committerDanilo M. <danix@danix.xyz>2026-06-24 16:38:45 +0200
commit9fb5b8b84b7822eb8a5aff2b0aaa176a15ff7a4f (patch)
tree5c6fe749a03736e78f3b5f6a9dacbfbe41ffdb18
parent492152f91a5d5668b384916321ae1b59c72bfb43 (diff)
downloadsbo-batch-tester-9fb5b8b84b7822eb8a5aff2b0aaa176a15ff7a4f.tar.gz
sbo-batch-tester-9fb5b8b84b7822eb8a5aff2b0aaa176a15ff7a4f.zip
Add cache_path + cache_store + tests
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
-rwxr-xr-xsbo-batch-test25
-rwxr-xr-xtest-logic.sh15
2 files changed, 40 insertions, 0 deletions
diff --git a/sbo-batch-test b/sbo-batch-test
index 1e0020c..c5e6cf1 100755
--- a/sbo-batch-test
+++ b/sbo-batch-test
@@ -342,6 +342,31 @@ cache_decision() {
fi
}
+# cache_path <cat> <prog> <version> -> echoes the cached .txz path for that
+# version, or nothing. Used to installpkg a cached dep.
+cache_path() {
+ local cat="$1" prog="$2" version="$3"
+ [[ -z "$PKG_CACHE" ]] && return
+ local dir="$PKG_CACHE/$cat/$prog"
+ local f newest=""
+ for f in "$dir/$prog"-*.t?z; do
+ [[ -e "$f" ]] || continue
+ [[ -z "$newest" || "$f" -nt "$newest" ]] && newest="$f"
+ done
+ [[ -z "$newest" ]] && return
+ [[ "$(_cache_ver_of "$prog" "$(basename "$newest")")" == "$version" ]] && echo "$newest"
+}
+
+# cache_store <cat> <prog> <src-txz> -> clear the prog dir, copy src in.
+cache_store() {
+ local cat="$1" prog="$2" src="$3"
+ [[ -z "$PKG_CACHE" ]] && return
+ local dir="$PKG_CACHE/$cat/$prog"
+ mkdir -p "$dir"
+ rm -f "$dir"/*.t?z
+ cp -a "$src" "$dir/"
+}
+
# =============================================================================
# SBo tree lookup. Find the SlackBuild dir for a prog name across roots.
# Echoes the dir path, returns 0 if found, 1 otherwise.
diff --git a/test-logic.sh b/test-logic.sh
index 7575ea7..4505ecb 100755
--- a/test-logic.sh
+++ b/test-logic.sh
@@ -123,6 +123,21 @@ PKG_CACHE_SAVE="$PKG_CACHE"; PKG_CACHE=""
[[ "$(cache_decision net libfoo 1.1)" == "new" ]] && ok "empty PKG_CACHE disables (new)" || bad "disabled cache should be new, got [$(cache_decision net libfoo 1.1)]"
PKG_CACHE="$PKG_CACHE_SAVE"
+# cache_path returns the hit file for a matching version
+hit="$(cache_path net libfoo 1.1)"
+[[ "$hit" == "$PKG_CACHE/net/libfoo/libfoo-1.1-x86_64-1_danix.txz" ]] && ok "cache_path returns hit" || bad "cache_path wrong, got [$hit]"
+
+# cache_path empty when version does not match
+[[ -z "$(cache_path net libfoo 9.9)" ]] && ok "cache_path empty on miss" || bad "cache_path should be empty on miss"
+
+# cache_store evicts: prog dir holds exactly the new file
+srctmp=$(mktemp -d); : > "$srctmp/libfoo-1.2-x86_64-1_danix.txz"
+cache_store net libfoo "$srctmp/libfoo-1.2-x86_64-1_danix.txz"
+count=$(find "$PKG_CACHE/net/libfoo" -name '*.t?z' | wc -l)
+[[ "$count" -eq 1 ]] && ok "cache_store evicts to one file" || bad "cache_store left $count files"
+[[ -e "$PKG_CACHE/net/libfoo/libfoo-1.2-x86_64-1_danix.txz" ]] && ok "cache_store stored new file" || bad "cache_store did not store new file"
+rm -rf "$srctmp"
+
# --- result -----------------------------------------------------------------
echo
echo "$pass passed, $fail failed"