commit: 2f2a06f02cf8aebc5ed3d32cf9f395f4005a2621
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Jul 2 14:04:13 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=2f2a06f0
emerge-webrsync: parse FETCHCOMMAND only once in fetch_file()
Presently, the fetch_file() function considers the value of the
'FETCHCOMMAND' portage variable and composes a derivative command to be
conveyed to the eval builtin. Further, it does so on each and every
occasion that the function is called. Instead, have it compose the
command just once. This is accomplished by stashing the command in the
newly introduced 'fetchcommand' variable, residing in the global scope.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/emerge-webrsync | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync
index 936f832637..43427cfad7 100755
--- a/bin/emerge-webrsync
+++ b/bin/emerge-webrsync
@@ -196,8 +196,28 @@ is_uint() {
fetch_file() {
# shellcheck disable=2034
local URI=$1 FILE=$2
+
+ if [[ ! ${fetchcommand} ]]; then
+ fetchcommand=$(get_fetchcommand)
+ fi
+
+ einfo "Fetching file ${FILE} ..."
+
+ if [[ ${fetchcommand} != @(curl|wget)[[:blank:]]* ]]; then
+ rm -f -- "${DISTDIR}/${FILE}"
+ fi
+
+ # Already set DISTDIR=
+ if ! eval "${fetchcommand}" || [[ ! -s ${DISTDIR}/${FILE} ]]; then
+ rm -f -- "${DISTDIR}/${FILE}"
+ return 1
+ fi
+}
+
+get_fetchcommand() {
local cmd_name cmd_args opts
+ # shellcheck disable=2153
read -rd '' cmd_name cmd_args <<<"${FETCHCOMMAND}"
case ${cmd_name} in
@@ -214,18 +234,11 @@ fetch_file() {
fi
;;
*)
- cmd_name=${FETCHCOMMAND}
- cmd_args=
- rm -f -- "${DISTDIR}/${FILE}"
+ printf '%s\n' "${FETCHCOMMAND}"
+ return
esac
- einfo "Fetching file ${FILE} ..."
-
- # Already set DISTDIR=
- if ! eval "${cmd_name} ${opts} ${cmd_args}" || [[ ! -s
${DISTDIR}/${FILE} ]]; then
- rm -f -- "${DISTDIR}/${FILE}"
- return 1
- fi
+ printf '%s\n' "${cmd_name} ${opts} ${cmd_args}"
}
check_file_digest() {
@@ -683,5 +696,6 @@ if [[ -n "${PORTAGE_NICENESS}" ]]; then
renice "${PORTAGE_NICENESS}" $$ > /dev/null
fi
+unset -v fetchcommand
declare -A opt=()
main "$@"