[Fix] nvm install: explain native Windows curl write failures

Refs #3391.
This commit is contained in:
Oikantik Basu authored and Jordan Harband committed 2026-11-24 19:09:58 +05:30
1 parent 41041a99ca
commit 74544c12f4
2 files changed
+66

No files matched your search

+10
View File
@@ -4389,10 +4389,20 @@ nvm_download_artifact() {
UNVERIFIED_TARBALL="${UNVERIFIED_DIR}/${SLUG}.${COMPRESSION}"
nvm_err "Downloading $(nvm_sanitize_url "${TARBALL_URL}")..."
local DOWNLOAD_STATUS
# stdout is reserved for the tarball path, so nothing the downloader prints may reach it
nvm_download -L -C - "${PROGRESS_BAR}" "${TARBALL_URL}" -o "${UNVERIFIED_TARBALL}" >&2 || {
DOWNLOAD_STATUS=$?
command rm -rf "${UNVERIFIED_DIR}" "${tmpdir}"
nvm_err "download from $(nvm_sanitize_url "${TARBALL_URL}") failed"
# curl returns 23 when it cannot write the output file.
if [ "${DOWNLOAD_STATUS}" -eq 23 ] && [ "$(nvm_get_os)" = 'win' ]; then
case "$(command curl -V 2>/dev/null)" in
'curl '*'(Windows)'*)
nvm_err 'Native Windows curl may not be able to write POSIX paths. Install curl for your shell environment and put it first on PATH.'
;;
esac
fi
return 4
}
@@ -0,0 +1,56 @@
#!/bin/sh
: nvm.sh
NVM_ENV=testing \. ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; exit 1; }
WORK="$(mktemp -d "${TMPDIR:-/tmp}/nvm-windows-curl.XXXXXX")" || exit 1
trap 'command rm -rf "${WORK}"' EXIT
NVM_DIR="${WORK}/nvm"
NVM_OFFLINE=0
nvm_get_mirror() { echo 'https://node.example.invalid/dist'; }
nvm_get_checksum_binary() { echo 'sha256sum'; }
nvm_get_checksum() { echo 'checksum'; }
nvm_get_os() { echo "${TEST_OS}"; }
make_fake_curl "${WORK}/bin" 'exit "${TEST_CURL_EXIT}"' || die 'could not create curl fixture'
PATH="${WORK}/bin:${PATH}"
export PATH TEST_CURL_EXIT
assert_download_failure() {
try_err nvm_download_artifact node binary std v20.0.0
[ "${CAPTURED_EXIT_CODE}" = 4 ] || die "expected artifact failure (4), got ${CAPTURED_EXIT_CODE}"
}
TEST_OS=win
TEST_CURL_EXIT=23
VERSION_MESSAGE='curl 8.23.0 (Windows) libcurl/8.23.0 Schannel'
HINT='Install curl for your shell environment'
assert_download_failure
case "${CAPTURED_STDERR}" in
*"${HINT}"*) ;;
*) die "the native Windows curl write failure needs a diagnostic; got: ${CAPTURED_STDERR}" ;;
esac
TEST_OS=linux
assert_download_failure
case "${CAPTURED_STDERR}" in
*"${HINT}"*) die 'the diagnostic should not appear on Linux' ;;
esac
TEST_OS=win
VERSION_MESSAGE='curl 8.23.0 (x86_64-pc-cygwin) libcurl/8.23.0'
assert_download_failure
case "${CAPTURED_STDERR}" in
*"${HINT}"*) die 'the diagnostic should not appear with Cygwin curl' ;;
esac
VERSION_MESSAGE='curl 8.23.0 (Windows) libcurl/8.23.0 Schannel'
TEST_CURL_EXIT=22
assert_download_failure
case "${CAPTURED_STDERR}" in
*"${HINT}"*) die 'the diagnostic should not appear for an HTTP failure' ;;
esac