commit: a3dfcf3148506ff4f7044b0266c5a9a15cdd7663
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue May 27 18:58:19 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 30 08:14:26 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a3dfcf31
phase-helpers.sh: use hash to gauge deb2targz availability
Presently, the unpack() function uses the type builtin to determine
whether deb2targz is present in PATH.
type -P deb2targz >/dev/null # proves that deb2targz is in PATH
deb2targz "${basename}" # deb2targz is then invoked in this manner
However, using type -P in this way is questionable. While type -P does
coerce bash into performing a PATH search, the manner in which deb2targz
is invoked still permits for deb2targz to be a function - even an alias
in the case that the expand_aliases option is enabled. Put another way,
type -P is worth using where the pathname of an executable must be
determined and subsequently referenced. Given that no such requirement
is implied, use the hash builtin to determine whether deb2targz is
available as a command. This has the advantage of pre-warming the cache
that the shell employs for Command Search and Execution.
Also, perform the command search before potentially performing a command
substitution for ar --version. The latter operation will almost
certainly be more expensive than the former.
It should be noted that the revised approach incurs fewer dup2(2) calls,
owing to STDERR being redirected just once.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/phase-helpers.sh | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 7ae983ccb7..4c76d385ed 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -470,8 +470,7 @@ unpack() {
# `deb2targz` installed, prefer it over `ar`
for that
# reason. We just make sure on AIX `deb2targz`
is
# installed.
- if [[ $(ar --version 2>/dev/null) != "GNU ar"*
]] && \
- type -P deb2targz > /dev/null; then
+ if { hash deb2targz && [[ $(ar --version) !=
"GNU ar"* ]]; } 2>/dev/null; then
# deb2targz always extracts into the
same directory as
# the source file, so create a symlink
in the current
# working directory if necessary.