fetchurl: fix handling of fallback URLs#470643
Conversation
Without the change fallback to `urls = []` does not
work as `$urls` evaluates on ony first entry. Use
`${urls[@]}` instead.
Example derivation that is fixed in `master` is
`xterm.src`:
Before:
$ nix build --no-link -f. xterm.src --rebuild -L
xterm> structuredAttrs is enabled
...
xterm> trying ftp://ftp.invisible-island.net/xterm/xterm-403.tgz
...
xterm> curl: (67) Access denied: 550
xterm> error: cannot download xterm-403.tgz from any mirror
After:
$ nix build --no-link -f. xterm.src --rebuild -L
xterm> structuredAttrs is enabled
...
xterm> trying ftp://ftp.invisible-island.net/xterm/xterm-403.tgz
...
xterm> curl: (67) Access denied: 550
...
xterm> trying https://invisible-mirror.net/archives/xterm/xterm-403.tgz
xterm> % Total % Received % Xferd Average Speed Time Time Time Current
xterm> Dload Upload Total Spent Left Speed
xterm> 100 1577k 100 1577k 0 0 703670 0 0:00:02 0:00:02 --:--:-- 703866
|
Thank you for fixing (one of) the leftover of PR #464475! Could we add a test case to guard the use of |
| fi | ||
| fi | ||
| done | ||
| urls="$urls2" |
There was a problem hiding this comment.
This is essentially equivalent to urls=("$urls2"). Even though it behaves like a plain variable, it is probably not ideal in the long run.
Nevertheless, it is still a good workaround.
Pinging @wolfgangwalther @MattSturgeon for input.
There was a problem hiding this comment.
Since spaces are invalid in URLs, this should be OK in practice, right?
There was a problem hiding this comment.
When I initially looked, my reaction was “let's just use arrays correctly and consistently.” But yes, spaces being invalid makes it mostly a non-issue in practice.
One potential subtlety is what error you get when you pass an invalid URL with a space... If we handle arrays correctly, then the error will come from passing curl an invalid URL. With the current implementation, the error will instead show up as passing curl multiple URL fragments.
While I'd like to see this implementation cleaned up, for me it doesn't block this PR.
There was a problem hiding this comment.
My main concern is how would users access urls in postFetch. This fix allows accessing it as "$urls", which is compatible with pre-structured-attrs behavior, but
- People and tools would expect
urlsbe passed as a Bash array when[[ -n "${__structuredAttes-}" ]]. declare -p urlswill show it's a Bash array, but it cnnot be accessed as such.- If users try to access
urlsinnetrcPhase, they need to Access it as a Bash array.
There was a problem hiding this comment.
While I'd like to see this implementation cleaned up, for me it doesn't block this PR.
I agree. Let's merge it first.
There was a problem hiding this comment.
I was wrong about the "behave like a plain variable" part.
This fix is bugged -- it doesn't work the way we have thought.
$ foo=(a b)
$ declare -p foo
declare -a foo=([0]="a" [1]="b")
$ foo="${foo[*]}"
$ declare -p foo
declare -a foo=([0]="a b" [1]="b")
$ declare foo="${foo[*]}"
$ declare -p foo
declare -a foo=([0]="a b b" [1]="b")There was a problem hiding this comment.
You are showing how foo="${foo[*]}" doesn't work as expected. But we don't do urls="${urls2[*]}", we do urls="$urls2". So I don't see the connection, yet.
There was a problem hiding this comment.
But we don't do
urls=\"${urls2[*]}\", we dourls=\"$urls2\".
The problemis the same. It is essentially urls[0]=$urls2. We thought we were rewrititng urls, but it is just urls[0].
There was a problem hiding this comment.
Ah, I found the mistake in my test-case. It's not exactly the same behavior as above, but yes only the first element is replaced with the other first element.
| fi | ||
| fi | ||
| done | ||
| urls="$urls2" |
There was a problem hiding this comment.
When I initially looked, my reaction was “let's just use arrays correctly and consistently.” But yes, spaces being invalid makes it mostly a non-issue in practice.
One potential subtlety is what error you get when you pass an invalid URL with a space... If we handle arrays correctly, then the error will come from passing curl an invalid URL. With the current implementation, the error will instead show up as passing curl multiple URL fragments.
While I'd like to see this implementation cleaned up, for me it doesn't block this PR.
Without the change fallback to
urls = []does not work as$urlsevaluates on ony first entry. Use${urls[@]}instead.Example derivation that is fixed in
masterisxterm.src:Before:
After:
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.