Skip to content

Commit 2c5a9b8

Browse files
authored
Merge pull request #266 from myoshi2891/dev-from-macmini
Add trap to ensure temp file cleanup in SRI script
2 parents 2c2282e + 0ca9ac2 commit 2c5a9b8

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

calc_sri_fix.sh

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
set -euo pipefail
44

5+
# calculate_sri downloads the given URL, computes the SHA-384 SRI hash of its content (base64) and echoes a line "<url> sha384-<base64_hash>".
56
calculate_sri() {
67
url="$1"
78
temp_file=$(mktemp)
9+
trap 'rm -f "$temp_file"' RETURN
810

911
# curl options: -f (fail on HTTP error), -S (show error), -s (silent equivalent), -L (follow redirects)
1012
if ! curl -fS -sL "$url" -o "$temp_file"; then
1113
echo "Error downloading $url" >&2
12-
rm -f "$temp_file"
1314
return 1
1415
fi
1516

1617
# Check for empty response
1718
if [ ! -s "$temp_file" ]; then
1819
echo "Error: Empty response from $url" >&2
19-
rm -f "$temp_file"
2020
return 1
2121
fi
2222

@@ -26,4 +26,4 @@ calculate_sri() {
2626
}
2727

2828
calculate_sri "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.js"
29-
calculate_sri "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.js"
29+
calculate_sri "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.js"

0 commit comments

Comments
 (0)