From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 5F4BC15807A for ; Sat, 07 Jun 2025 22:55:00 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 4C3793430F1 for ; Sat, 07 Jun 2025 22:55:00 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 7BB72110497; Sat, 07 Jun 2025 22:54:48 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 6AED8110497 for ; Sat, 07 Jun 2025 22:54:48 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 251763430C8 for ; Sat, 07 Jun 2025 22:54:48 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 941DB2921 for ; Sat, 07 Jun 2025 22:54:45 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1749336849.7f66a7b26c9caae12aaf2cc2bbe13a180a803fb9.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/ecompress X-VCS-Directories: bin/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 7f66a7b26c9caae12aaf2cc2bbe13a180a803fb9 X-VCS-Branch: master Date: Sat, 07 Jun 2025 22:54:45 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 73b666bc-c2dd-426d-9f1e-b3b8e4426e95 X-Archives-Hash: aa1ba49207ac938cd8080a7312315a3c commit: 7f66a7b26c9caae12aaf2cc2bbe13a180a803fb9 Author: Kerin Millar plushkava net> AuthorDate: Thu Aug 11 00:09:52 2022 +0000 Commit: Sam James gentoo org> CommitDate: Sat Jun 7 22:54:09 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7f66a7b2 ecompress: improve the guess_suffix() function This commit makes some changes to the guest_suffix() function, which are described herewith. Localise its variables. Also, localise the '-' parameter so that the enablement of the "errexit" shell option is scoped to the function. Don't make use of brace expansion to print a range of numbers. Doing so requires for the entire range be expanded as a series of words beforehand. Even for a narrow range of 0..1000, there is a measurable impact on memory usage. Instead, use a C-style for loop. Dispense with the clumsy combination of command substitution, echo invocation and pathname expansion. Instead, iterate over compress?*, assigning the first existing match to the 'suffix' variable. Prior to returning, don't print the suffix unless one was discovered, and do so using printf rather than echo. Further, ensure that the return value is something other than 0 in the case that no suffix is found. Note that the caller is now able to invoke die if something goes wrong. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/ecompress | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bin/ecompress b/bin/ecompress index 389af4be7d..ec74bdfc25 100755 --- a/bin/ecompress +++ b/bin/ecompress @@ -90,6 +90,8 @@ do_queue() { } guess_suffix() { + local - f i suffix + set -e tmpdir="${T}"/.ecompress$$.${RANDOM} @@ -99,19 +101,25 @@ guess_suffix() { # 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 - echo {0..1000} > compressme + for (( i = 0; i <= 1000; i++ )); do + printf '%s ' "${i}" + done > compressme ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS} compressme > /dev/null # If PORTAGE_COMPRESS_FLAGS contains -k then we need to avoid # having our glob match the uncompressed file here. - suffix=$(echo compressme.*) - [[ -z ${suffix} || "${suffix}" == "compressme.*" ]] && \ - suffix=$(echo compressme*) - suffix=${suffix#compressme} + for f in compressme?*; do + if [[ -e ${f} ]]; then + suffix=${f#compressme} + break + fi + done cd / rm -rf -- "${tmpdir}" - echo "${suffix}" + + set +e + [[ ${suffix} ]] && printf '%s\n' "${suffix}" } fix_symlinks() {