Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869# shellcheck shell=bash# link the paths of each cache entry to its directory on the cache volume# the engine adds one restore call for each entry after this scriptset -eu
root=$TANGLED_CACHE
# the mac mounts the volume as root, so take it for the step user[ -w "$root" ] || sudo chown "$(id -u)" "$root"
# a short hash of standard input, with the tool that this os hasdigest() { if command -v sha256sum >/dev/null; then sha256sum; else shasum -a 256; fi | cut -c1-16}
# usage: restore key hash fallback, then one or more paths# each key keeps one directory, named by the hash of its hash filesrestore() { key=$1 name=$2 fallback=$3 shift 3 dir=$root/$key want=$root/$key/$name state=restored
if [ ! -d "$want" ]; then # the key has at most one other directory, from the hash before this one prev= if [ "$fallback" = true ]; then for d in "$dir"/*/; do [ -d "$d" ] && prev=${d%/} done fi mkdir -p "$dir" if [ -n "$prev" ]; then # take over the old hash's files instead of starting empty mv "$prev" "$want" state="restored from an older hash" else mkdir "$want" state="empty, first run with this key" fi fi
# remove the directories of old hashes, and make read-only files such as the go module cache removable first find "$dir" -mindepth 1 -maxdepth 1 ! -name "$name" -exec chmod -R u+w {} + -exec rm -rf {} +
# each path gets a numbered directory in the key's directory i=0 for p in "$@"; do mkdir -p "$want/$i" if [ -L "$p" ]; then # a link from an earlier restore in this workspace rm "$p" elif [ -d "$p" ]; then # a directory that is already there, such as one in the repository, moves onto the volume cp -a "$p/." "$want/$i/" chmod -R u+w "$p" rm -rf "$p" elif [ -e "$p" ]; then echo "Cache $key: $p is a file, not a directory; it isn't cached." >&2 i=$((i + 1)) continue fi # the step then reads and writes the volume through the link, so nothing is copied back mkdir -p "$(dirname "$p")" ln -s "$want/$i" "$p" i=$((i + 1)) done echo "Cache $key: $state."}