aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-08-29 16:05:23 +0200
committerMatěj Cepl <mcepl@cepl.eu>2024-08-29 16:05:23 +0200
commit8c953c0a42d9af2e43172ab09d0b175ea93b6925 (patch)
treeeac0317313c83d3d484a9f7a51740ae424f57ea7
parent1eec563f3239ff91a27f9bc85573e6deadb91547 (diff)
downloadtmp-8c953c0a42d9af2e43172ab09d0b175ea93b6925.tar.gz
fix: use trap instead of complicated control of the COMPRESSED state
-rwxr-xr-xtmp.sh10
1 files changed, 1 insertions, 9 deletions
diff --git a/tmp.sh b/tmp.sh
index 4925804..2c499c2 100755
--- a/tmp.sh
+++ b/tmp.sh
@@ -106,11 +106,10 @@ for processed_file in "${@:1}" ; do
debug "file ${processed_file} should be compressed (${st} b)"
gzip --keep --best "${processed_file}" || error 'Compressing the file failed!'
fname="${processed_file}.gz"
- COMPRESSED=1
+ trap 'rm -f "${fname}"' EXIT
else
debug "file ${processed_file} should not be compressed (${st} b)"
fname="${processed_file}"
- COMPRESSED=0
fi
chmod 644 "$fname"
@@ -136,11 +135,4 @@ for processed_file in "${@:1}" ; do
shortened_URL="$(curl -s "${SHORTEN_API}""${safe_target_URL}")"
echo "${shortened_URL}"
fi
-
- # The script should have no side-effects
- if [ "${COMPRESSED}" -eq 1 ] ; then
- rm "${modified_fname}"
- else
- mv "${modified_fname}" "${fname}"
- fi
done