commit:     79bff4fada524898465e0dcf1148a2e02a31121e
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Jul  3 16:33:43 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jul  4 02:17:04 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=79bff4fa

emerge-webrsync: refrain from calling die() before it is declared

Presently, the emerge-webrsync script begins by trying to locate and
store the paths of the emerge(1) and portageq utilities. In the case
that either is missing, a diagnostic message is displayed before
exiting, with the aid of the die() function. However, the function will
not yet have been declared.

Address this issue by avoiding the use of the die() function at that
particular juncture. It was once the case that the function was declared
prior, but the declaration was deliberately repositioned so as to
override the over-engineered and unwieldy function of the same name from
the "isolated-functions.sh" unit.

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

 bin/emerge-webrsync | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync
index 43427cfad7..2719e60486 100755
--- a/bin/emerge-webrsync
+++ b/bin/emerge-webrsync
@@ -450,11 +450,11 @@ sync_local() {
 
        if (( ! from_portage )) && contains_word metadata-transfer 
"${FEATURES}"; then
                einfo "Updating cache ..."
-               "${emerge}" --metadata
+               "${path_of[emerge]}" --metadata
        fi
 
        if (( ! from_portage )) && contains_word news "${FEATURES}"; then
-               "${emerge}" --check-news --quiet
+               "${path_of[emerge]}" --check-news --quiet
        fi
 
        return 0
@@ -628,12 +628,13 @@ from_portage=${PORTAGE_BIN_PATH:+1}
 
 # Use emerge and portageq from the same directory/prefix as the current script,
 # so that we don't have to rely on PATH including the current EPREFIX.
-if ! emerge=$(PATH=${BASH_SOURCE%/*}:${PATH} type -P emerge); then
-       die "could not find 'emerge'; aborting"
-fi
-if ! portageq=$(PATH=${BASH_SOURCE%/*}:${PATH} type -P portageq); then
-       die "could not find 'portageq'; aborting"
-fi
+declare -A path_of=()
+for bin in emerge portageq; do
+       if ! path_of[$bin]=$(PATH=${BASH_SOURCE%/*}:${PATH} type -P "${bin}"); 
then
+               printf >&2 '%s: unable to locate the "%s" binary; aborting\n' 
"$0" "${bin}"
+               exit 1
+       fi
+done
 
 portage_vars=(
        DISTDIR
@@ -657,7 +658,7 @@ portage_vars=(
        https_proxy
 )
 
-eval "$("${portageq}" envvar -v "${portage_vars[@]}")"
+eval "$("${path_of[portageq]}" envvar -v "${portage_vars[@]}")"
 export http_proxy https_proxy ftp_proxy
 
 source "${PORTAGE_BIN_PATH:?}"/isolated-functions.sh || exit

Reply via email to