Commit fc180191 authored by Yueh-Shun Li's avatar Yueh-Shun Li
Browse files

fetchurl: builder.sh: handle `urls` as a Bash array



Clean up leftover for commit cd13136f
("fetchurl: use __structuredAttrs = true and pass curlOptsList directly")

Continue the work of commit 23236b33
("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: default avatarMatt Sturgeon <matt@sturgeon.me.uk>
Co-authored-by: default avatarWolfgang Walther <walther@technowledgy.de>
parent 1e5ca4ea
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -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/*)