From fc180191def1822535c9d54e71f56574b1964fe8 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Thu, 18 Dec 2025 06:20:24 +0800 Subject: [PATCH] fetchurl: builder.sh: handle `urls` as a Bash array Clean up leftover for commit cd13136f036d ("fetchurl: use __structuredAttrs = true and pass curlOptsList directly") Continue the work of commit 23236b331d06 ("fetchurl: fix handling of fallback URLs"), addressing a Bash array re-assignment quirk: when assigning a Bash array variable as if it were a plain variable, the value goes to the first element, and the rest of the array stays the same. ```console $ foo=(a b) $ declare -p foo declare -a foo=([0]="a" [1]="b") $ foo="c d" $ declare -p foo declare -a foo=([0]="c d" [1]="b") ``` Don't rewrite the `${urls[@]}` with resolved URLs, but hold them with `${resolvedUrls[@]}` instead. Co-authored-by: Matt Sturgeon Co-authored-by: Wolfgang Walther --- pkgs/build-support/fetchurl/builder.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh index 9add2b27a072..228fcd2ed185 100644 --- a/pkgs/build-support/fetchurl/builder.sh +++ b/pkgs/build-support/fetchurl/builder.sh @@ -124,10 +124,10 @@ tryHashedMirrors() { # URL list may contain ?. No glob expansion for that, please set -o noglob -urls2= +resolvedUrls=() for url in "${urls[@]}"; do if test "${url:0:9}" != "mirror://"; then - urls2="$urls2 $url" + resolvedUrls+=("$url") else url2="${url:9}"; echo "${url2/\// }" > split; read site fileName < split #varName="mirror_$site" @@ -142,18 +142,17 @@ for url in "${urls[@]}"; do if test -n "${!varName}"; then mirrors="${!varName}"; fi for url3 in $mirrors; do - urls2="$urls2 $url3$fileName"; + resolvedUrls+=("$url3$fileName"); done fi fi done -urls="$urls2" # Restore globbing settings set +o noglob if test -n "$showURLs"; then - echo "$urls" > $out + echo "${resolvedUrls[*]}" > $out exit 0 fi @@ -165,7 +164,7 @@ fi set -o noglob success= -for url in $urls; do +for url in "${resolvedUrls[@]}"; do if [ -z "$postFetch" ]; then case "$url" in https://github.com/*/archive/*)