Skip to content

Commit 5685344

Browse files
authored
Merge pull request #28 from leowmjw/fix-issue-27
Summary: Fix issue #27
2 parents b42887b + cd0d630 commit 5685344

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

mash

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,23 @@ run() {
4646
fi
4747

4848
get_etag() {
49-
grep -i ETag "$CACHE/headers.txt" | sed -e 's/ETag: "\(.*\)"/\1/I' | tr -d '\r'
49+
# Swallow error when CACHE does not exist
50+
# Always allow even ETAG invalid to not fail pipeline
51+
grep -i ETag "$CACHE/headers.txt" 2>/dev/null | sed -e 's/ETag: "\(.*\)"/\1/I' | tr -d '\r' || true
5052
}
5153

52-
if [ -f "$CACHE/headers.txt" ] && ETAG=$(get_etag); then
54+
ETAG=$(get_etag)
55+
# If invalid ETAG but CACHE exists: remove it
56+
if [ -z "$ETAG" ] && [ -d "$CACHE" ]; then
57+
echo "Cache in bad state; will remove $CACHE"
58+
rm -rf "$CACHE"
59+
fi
60+
61+
if [ -f "$CACHE/headers.txt" ] && [ ! -z "$ETAG" ]; then
5362
ETAG=(--header If-None-Match:\ $ETAG)
5463
else
5564
mkdir -p "$CACHE"
65+
ETAG=()
5666
fi
5767

5868
URL="https://pkgxdev.github.io/mash/$SCRIPTNAME"

0 commit comments

Comments
 (0)