commit:     856d5481d8da8b0f6945812cdf6aa4f1119a0c9e
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri May 30 03:53:55 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jun  1 21:41:59 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=856d5481

phase-helpers.sh: use hash to gauge gfind(1) availability

Presently, the eapply() function uses the type builtin to determine
whether gfind(1) is present in PATH. To do so is questionable. While
type -P does coerce bash into performing a PATH search, the manner in
which gfind is invoked still permits for it to be a function - even an
alias in the case that the expand_aliases option is enabled. Instead,
use the hash builtin to determine whether gfind is available as a
command. This has the advantage 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-helpers.sh | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 365d072317..bef0abbcc9 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -981,13 +981,6 @@ if ___eapi_has_eapply; then
                local f failed patch_cmd path
                local -a files operands options
 
-               # for bsd userland support, use gpatch if available
-               if type -P gpatch >/dev/null; then
-                       patch_cmd=gpatch
-               else
-                       patch_cmd=patch
-               fi
-
                _eapply_get_files() {
                        local LC_ALL=POSIX f
 
@@ -1045,6 +1038,11 @@ if ___eapi_has_eapply; then
 
                if (( ! ${#operands[@]} )); then
                        die "eapply: no operands were specified"
+               elif hash gpatch 2>/dev/null; then
+                       # for bsd userland support, use gpatch if available
+                       patch_cmd=gpatch
+               else
+                       patch_cmd=patch
                fi
 
                for path in "${operands[@]}"; do

Reply via email to