commit:     c86cba39d73be8699ec6b44b8057985e8604e3eb
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Jun  8 16:35:53 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jun  9 02:51:08 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c86cba39

ecompress: don't open .ecompress_skip_files for writing twice

Presently, the do_ignore() function may open the ".ecompress_skip_files"
twice for writing. Instead, open the file once and keep track of its
file descriptor until such time as it is no longer needed, upon which
the file is closed.

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

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

diff --git a/bin/ecompress b/bin/ecompress
index eb1be9e5ac..3266c1c735 100755
--- a/bin/ecompress
+++ b/bin/ecompress
@@ -8,7 +8,10 @@ source "${PORTAGE_BIN_PATH}"/isolated-functions.sh || exit 1
 do_ignore() {
        local -x LC_ALL= LC_COLLATE=C
        local -a skip_dirs
-       local skip
+       local fileno skip
+
+       # Open the file in which the skippable paths will be recorded.
+       exec {fileno}>"${T}/.ecompress_skip_files" || die
 
        for skip; do
                if [[ ${skip} == *$'\n'* ]]; then
@@ -22,7 +25,7 @@ do_ignore() {
                        && printf '%s\n' "${EPREFIX}/${skip#/}" \
                        || ! break
                fi
-       done > "${T}/.ecompress_skip_files" || die
+       done >&"${fileno}" || die
 
        if (( ${#skip_dirs[@]} )); then
                while IFS= read -rd '' skip; do
@@ -30,12 +33,15 @@ do_ignore() {
                        printf '%s\n' "${skip#"${D%/}"}" || ! break
                done \
                < <(printf '%s\0' "${skip_dirs[@]}" | find0 -name '*.ecompress' 
! -path $'*\n*' -print0 -delete) \
-               >> "${T}/.ecompress_skip_files" || die
+               >&"${fileno}" || die
 
                # Check whether the invocation of find(1) succeeded.
                wait "$!" || die
        fi
 
+       # Close the file in which the skippable paths have been recorded.
+       exec {fileno}>&- || die
+
        # shellcheck disable=2015
        if [[ -s ${T}/.ecompress_skip_files && -s 
${T}/.ecompress_had_precompressed ]]; then
                # Filter skipped files from ${T}/.ecompress_had_precompressed,

Reply via email to