commit:     8c824b934b77a8d23f82e07606e9f8be707a8cf4
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Jun  5 05:52:00 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Jun  5 11:22:05 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=8c824b93

phase-functions.sh: reduce the degree of indentation in __dyn_install()

Presently, the __dyn_install() function guards the routine that records
the sizes of WORKDIR and D with a test for the existence of the du(1)
utility. Decrease the indentation level of the entire routine by
repositioning the test and simply exiting the subshell in the highly
unlikely event that the utility be missing. It is unclear to me why the
test is present, given that it is a standard utility and is required by
POSIX to exist.

Further, use the hash builtin instead of the type builtin. While type -P
does coerce bash into performing a PATH search, the manner in which du
is invoked still permits for it to be a function or alias. Using hash
also confers the benefit of pre-warming the cache that the shell employs
for Command Search and Execution.

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

 bin/phase-functions.sh | 102 ++++++++++++++++++++++++-------------------------
 1 file changed, 51 insertions(+), 51 deletions(-)

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index 19b643d9d5..a35cd5129e 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -628,58 +628,58 @@ __dyn_install() {
        __vecho
        __ebuild_phase post_src_install
 
-       # record build & installed size in build log
-       if type -P du &>/dev/null; then
-               # subshell to avoid polluting the caller env with the helper
-               # functions below
-               (
-                       local nsz=( $(du -ks "${WORKDIR}") )
-                       local isz=( $(du -ks "${D}") )
-                       # align $1 to the right to the width of the widest of 
$1 and $2
-                       padl() {
-                               local s1=$1
-                               local s2=$2
-                               local width=${#s1}
-                               [[ ${#s2} -gt ${width} ]] && width=${#s2}
-                               printf "%*s" ${width} "${s1}"
-                       }
-
-                       # transform number in KiB into MiB, GiB or TiB based on 
size
-                       human() {
-                               local s1=$1
-                               local units=( KiB MiB GiB TiB )
-
-                               s1=$((s1 * 10))
-                               while [[ ${s1} -gt 10240 && ${#units[@]} -gt 1 
]] ; do
-                                       s1=$((s1 / 1024 ))
-                                       units=( ${units[@]:1} )
-                               done
-
-                               local r=${s1: -1}
-                               s1=$((s1 / 10))
-                               printf "%s.%s %s" "${s1}" "${r}" "${units[0]}"
-                       }
-
-                       size() {
-                               local s1=$1
-                               local s2=$2
-                               local out="$(padl "${s1}" "${s2}") KiB"
-
-                               if [[ ${s1} -gt 1024 ]] ; then
-                                       s1=$(human ${s1})
-                                       if [[ ${s2} -gt 1024 ]] ; then
-                                               s2=$(human ${s2})
-                                               s1=$(padl "${s1}" "${s2}")
-                                       fi
-                                       out+=" (${s1})"
+       # Record the sizes of WORKDIR and D to the build log. Employ a subshell
+       # so as to avoid polluting the caller's environment with several helper
+       # functions.
+       (
+               hash du 2>/dev/null || exit 0
+
+               local nsz=( $(du -ks "${WORKDIR}") )
+               local isz=( $(du -ks "${D}") )
+               # align $1 to the right to the width of the widest of $1 and $2
+               padl() {
+                       local s1=$1
+                       local s2=$2
+                       local width=${#s1}
+                       [[ ${#s2} -gt ${width} ]] && width=${#s2}
+                       printf "%*s" ${width} "${s1}"
+               }
+
+               # transform number in KiB into MiB, GiB or TiB based on size
+               human() {
+                       local s1=$1
+                       local units=( KiB MiB GiB TiB )
+
+                       s1=$((s1 * 10))
+                       while [[ ${s1} -gt 10240 && ${#units[@]} -gt 1 ]] ; do
+                               s1=$((s1 / 1024 ))
+                               units=( ${units[@]:1} )
+                       done
+
+                       local r=${s1: -1}
+                       s1=$((s1 / 10))
+                       printf "%s.%s %s" "${s1}" "${r}" "${units[0]}"
+               }
+
+               size() {
+                       local s1=$1
+                       local s2=$2
+                       local out="$(padl "${s1}" "${s2}") KiB"
+
+                       if [[ ${s1} -gt 1024 ]] ; then
+                               s1=$(human ${s1})
+                               if [[ ${s2} -gt 1024 ]] ; then
+                                       s2=$(human ${s2})
+                                       s1=$(padl "${s1}" "${s2}")
                                fi
-                               echo "${out}"
-                       }
-                       einfo "Final size of build directory: $(size ${nsz[0]} 
${isz[0]})"
-                       einfo "Final size of installed tree:  $(size ${isz[0]} 
${nsz[0]})"
-               )
-               __vecho
-       fi
+                               out+=" (${s1})"
+                       fi
+                       echo "${out}"
+               }
+               einfo "Final size of build directory: $(size ${nsz[0]} 
${isz[0]})"
+               einfo "Final size of installed tree:  $(size ${isz[0]} 
${nsz[0]})"
+       )
+       __vecho
 
        cd "${PORTAGE_BUILDDIR}"/build-info
        set -f

Reply via email to