diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2024-08-29 16:05:23 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-08-29 16:05:23 +0200 |
commit | 8c953c0a42d9af2e43172ab09d0b175ea93b6925 (patch) | |
tree | eac0317313c83d3d484a9f7a51740ae424f57ea7 | |
parent | 1eec563f3239ff91a27f9bc85573e6deadb91547 (diff) | |
download | tmp-8c953c0a42d9af2e43172ab09d0b175ea93b6925.tar.gz |
fix: use trap instead of complicated control of the COMPRESSED state
-rwxr-xr-x | tmp.sh | 10 |
1 files changed, 1 insertions, 9 deletions
@@ -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 |