From cd0d630751c83124459282bbd69ca0879713688e Mon Sep 17 00:00:00 2001 From: Michael Leow Date: Sat, 21 Feb 2026 19:57:17 +0800 Subject: [PATCH] Summary: Fix issue #27 Changeset: - Detect invalid ETAG and remove CACHE when that happens --- mash | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mash b/mash index 494ede3..41baa4c 100755 --- a/mash +++ b/mash @@ -46,13 +46,23 @@ run() { fi get_etag() { - grep -i ETag "$CACHE/headers.txt" | sed -e 's/ETag: "\(.*\)"/\1/I' | tr -d '\r' + # Swallow error when CACHE does not exist + # Always allow even ETAG invalid to not fail pipeline + grep -i ETag "$CACHE/headers.txt" 2>/dev/null | sed -e 's/ETag: "\(.*\)"/\1/I' | tr -d '\r' || true } - if [ -f "$CACHE/headers.txt" ] && ETAG=$(get_etag); then + ETAG=$(get_etag) + # If invalid ETAG but CACHE exists: remove it + if [ -z "$ETAG" ] && [ -d "$CACHE" ]; then + echo "Cache in bad state; will remove $CACHE" + rm -rf "$CACHE" + fi + + if [ -f "$CACHE/headers.txt" ] && [ ! -z "$ETAG" ]; then ETAG=(--header If-None-Match:\ $ETAG) else mkdir -p "$CACHE" + ETAG=() fi URL="https://pkgxdev.github.io/mash/$SCRIPTNAME"