commit: ddbd213e3ad2d1f340c5cd86b102cc1788b836b6
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jun 7 18:37:11 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Jun 7 22:54:16 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ddbd213e
ecompress: accelerate fix_symlinks() by having find(1) resolve targets
The GNU implementation of the find(1) utility offers some powerful
primaries. Enhance the performance of the fix_symlinks() function by
taking advantage of them. The exact manner in which this is accomplished
is described herewith.
Use the -xtype l primary so as not to waste any time processing
non-dangling symlinks. The shell is duly relieved of the need to test
for the existence of the link's target.
Use the -printf primary so as to print NUL-terminated pairs, where the
first item is the path of the symlink, and the second item its target.
Not only does this avoid an expensive invocation of readlink(1) for each
iteration of the loop but it also guarantees that any possible target
will be processed correctly. Hitherto, this had not been the case, for
the following reasons.
- the <newline> character can legally be present within a pathname
- readlink(1) arbitrarily produces a trailing <newline> character
- command substitutions strip all trailing <newline> characters
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/ecompress | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/bin/ecompress b/bin/ecompress
index 490fd8d345..b6063d87ce 100755
--- a/bin/ecompress
+++ b/bin/ecompress
@@ -138,11 +138,9 @@ fix_symlinks() {
# levels of indirection (see bug #470916).
while true ; do
something_changed=0
- while IFS= read -rd '' link; do
- [[ -e ${link} ]] && continue
-
- target1=$(readlink -- "${link}")
+ while IFS= read -rd '' link && IFS= read -rd '' target1; do
target2=${target1}${PORTAGE_COMPRESS_SUFFIX}
+
if [[ ${target2} == /* ]]; then
if [[ ! -f ${D%/}${target2} ]]; then
continue
@@ -155,7 +153,7 @@ fix_symlinks() {
rm -f -- "${link}" \
&& ln -snf -- "${target2}"
"${link}${PORTAGE_COMPRESS_SUFFIX}" \
|| return
- done < <(printf '%s\0' "${ED}" | find0 -type l -print0)
+ done < <(printf '%s\0' "${ED}" | find0 -type l -xtype l -printf
'%p\0%l\0')
# Check whether the invocation of find(1) succeeded.
wait "$!" || return