mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-11-26 18:52:55 +03:00
[Fix] nvm_download_artifact: without a checksum tool, fail before touching the cache or downloading
Previously, every download was refused only after it was fetched, a verified cached archive was deleted as "broken", and the source fallback then downloaded a second archive that was refused the same way, with no message saying what to install.
This commit is contained in:
2 files changed
+15
-2
No files matched your search
@@ -3916,6 +3916,12 @@ nvm_download_artifact() {
|
||||
return 4
|
||||
fi
|
||||
|
||||
# nothing can be verified without a checksum tool, so fail before touching the cache or downloading
|
||||
if ! nvm_get_checksum_binary >/dev/null; then
|
||||
nvm_err 'Install one of them so that nvm can verify downloads.'
|
||||
return 6
|
||||
fi
|
||||
|
||||
local CHECKSUM
|
||||
CHECKSUM="$(nvm_get_checksum "${FLAVOR}" "${TYPE}" "${VERSION}" "${SLUG}" "${COMPRESSION}")"
|
||||
|
||||
@@ -3941,7 +3947,7 @@ nvm_download_artifact() {
|
||||
fi
|
||||
nvm_compare_checksum "${TARBALL}" "${CHECKSUM}"
|
||||
nvm_err "Checksum check failed!"
|
||||
nvm_err "Removing the broken local cache..."
|
||||
nvm_err "Removing the unverified local cache..."
|
||||
command rm -rf "${TARBALL}"
|
||||
fi
|
||||
# `--offline` uses the cached archive without a checksum, so only a verified archive may ever sit at ${TARBALL}
|
||||
|
||||
@@ -4,7 +4,7 @@ WORK="${TMPDIR:-/tmp}/nvm_download_artifact_cache.$$"
|
||||
|
||||
cleanup () {
|
||||
command rm -rf "${WORK}"
|
||||
unset -f cleanup die download_offline nvm_get_mirror nvm_binary_available nvm_get_download_slug nvm_get_artifact_compression nvm_cache_dir nvm_get_checksum nvm_version_greater_than_or_equal_to nvm_download nvm_compute_checksum nvm_compare_checksum
|
||||
unset -f cleanup die download_offline nvm_get_mirror nvm_binary_available nvm_get_download_slug nvm_get_artifact_compression nvm_cache_dir nvm_get_checksum nvm_version_greater_than_or_equal_to nvm_download nvm_compute_checksum nvm_compare_checksum nvm_get_checksum_binary
|
||||
}
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
@@ -92,4 +92,11 @@ try nvm_download_artifact node binary std v20.0.0
|
||||
[ ! -e "${TEST_TARBALL}.unverified" ] || die 'verified download: expected no unverified download to remain in the cache'
|
||||
[ ! -e "${WORK}/downloaded-to-final-name" ] || die 'an unverified download was written to the final cache name, where an interrupted download would be left for --offline'
|
||||
|
||||
# without any checksum tool, nothing is downloaded and the verified cache is left alone
|
||||
nvm_get_checksum_binary() { return 1; }
|
||||
try nvm_download_artifact node binary std v20.0.0
|
||||
[ "${CAPTURED_EXIT_CODE}" = '6' ] || die "no checksum tool: expected exit code 6, got ${CAPTURED_EXIT_CODE}"
|
||||
[ "$(command cat "${TEST_TARBALL}")" = 'downloaded' ] || die "no checksum tool: expected the cached archive to be left alone, got >$(command cat "${TEST_TARBALL}")<"
|
||||
[ ! -e "${TEST_TARBALL}.unverified" ] || die 'no checksum tool: expected nothing to be downloaded'
|
||||
|
||||
cleanup
|
||||
Reference in new issue
Block a user