From 8c953c0a42d9af2e43172ab09d0b175ea93b6925 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Thu, 29 Aug 2024 16:05:23 +0200 Subject: fix: use trap instead of complicated control of the COMPRESSED state --- tmp.sh | 10 +--------- 1 file changed, 1 insertion(+), 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 -- cgit