mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-07-18 12:58:21 +08:00
[Fix] nvm_download, nvm_get_latest, install: only select a downloader that exists as an executable
`nvm_has` matches shell functions and aliases, but downloads now run via `command`, which skips them - a `curl` shell function with no curl binary on the PATH would select the curl path and fail with exit 127, instead of falling back to an available wget executable. The new `nvm_has_executable` helper resolves names the same way `command` does, so downloader selection and execution agree.
This commit is contained in:
@@ -45,4 +45,22 @@ nvm_curl_libz_support || die 'nvm_curl_libz_support used the shadowing curl func
|
||||
nvm_download -s 'http://example.com/' -o /dev/null || die 'nvm_download used the shadowing curl function and failed'
|
||||
grep -Fxq 'http://example.com/' "$ARGV_LOG" || die "nvm_download did not invoke the curl executable; got: $(cat "$ARGV_LOG")"
|
||||
|
||||
# when no curl executable exists, a shadowing curl shell function must not fool
|
||||
# downloader selection: nvm_download must fall back to the wget executable
|
||||
WGET_ONLY_BIN="$WORK/wget-only-bin"
|
||||
mkdir -p "$WGET_ONLY_BIN"
|
||||
{
|
||||
echo '#!/bin/sh'
|
||||
echo ': > "$ARGV_LOG"'
|
||||
echo 'for a in "$@"; do printf "%s\n" "$a" >> "$ARGV_LOG"; done'
|
||||
} > "$WGET_ONLY_BIN/wget"
|
||||
chmod +x "$WGET_ONLY_BIN/wget"
|
||||
|
||||
(
|
||||
PATH="$WGET_ONLY_BIN"
|
||||
export PATH
|
||||
nvm_download -s 'http://wget-fallback.example.com/' -o /dev/null
|
||||
) || die 'nvm_download did not fall back to wget when curl is only a shell function'
|
||||
grep -Fxq 'http://wget-fallback.example.com/' "$ARGV_LOG" || die "nvm_download did not invoke the wget executable; got: $(cat "$ARGV_LOG")"
|
||||
|
||||
cleanup
|
||||
|
||||
Reference in New Issue
Block a user