commit:     f7646fe7172fc33a73e8d1101e8036b61002dff1
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jun  7 11:40:34 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Jun  7 22:54:12 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=f7646fe7

ecompress: have guess_suffix() handle errors explicitly

The errexit option (set -e) is an inheritance of the old bourne shell,
and doesn't really work well with modern shell features. Have the
guess_suffix() function directly catch and handle errors instead.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/ecompress | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/bin/ecompress b/bin/ecompress
index cbde983742..8577c27168 100755
--- a/bin/ecompress
+++ b/bin/ecompress
@@ -102,21 +102,21 @@ do_queue() {
 }
 
 guess_suffix() {
-       local - f i suffix
+       local f i suffix
 
-       set -e
-
-       tmpdir="${T}"/.ecompress$$.${RANDOM}
-       mkdir -- "${tmpdir}"
-       cd -- "${tmpdir}"
+       tmpdir=${T}/.ecompress$$.${RANDOM}
+       mkdir -- "${tmpdir}" \
+       && cd -- "${tmpdir}" \
+       || return
 
        # We have to fill the file enough so that there is something
        # to compress as some programs will refuse to do compression
        # if it cannot actually compress the file
        for (( i = 0; i <= 1000; i++ )); do
-               printf '%s ' "${i}"
-       done > compressme
-       ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS} compressme > /dev/null
+               printf '%s ' "${i}" || ! break
+       done > compressme || return
+
+       ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS} compressme > /dev/null || 
return
 
        # If PORTAGE_COMPRESS_FLAGS contains -k then we need to avoid
        # having our glob match the uncompressed file here.
@@ -127,10 +127,10 @@ guess_suffix() {
                fi
        done
 
-       cd /
-       rm -rf -- "${tmpdir}"
+       cd / \
+       && rm -rf -- "${tmpdir}" \
+       || return
 
-       set +e
        [[ ${suffix} ]] && printf '%s\n' "${suffix}"
 }
 

Reply via email to