Improve nvm_download_artifact() process, fix #1291

- Delete broken/checksum not matched local cache
 - More output message.
Peter Dave Hello 2016-11-07 18:51:13 +08:00
parent 7ef38cf7e8
commit c5303a6973
1 changed files with 27 additions and 19 deletions

14
nvm.sh
View File

@ -1733,10 +1733,19 @@ nvm_download_artifact() {
TARBALL_URL="${MIRROR}/${SLUG}.tar.${COMPRESSION}"
fi
if [ -r "${TARBALL}" ]; then
nvm_err "Local cache found: $(nvm_sanitize_path "${TARBALL}")"
if nvm_compare_checksum "${TARBALL}" "${CHECKSUM}" >/dev/null 2>&1; then
nvm_err "Checksums match! Using existing downloaded archive $(nvm_sanitize_path "${TARBALL}")"
else
nvm_echo "Downloading ${TARBALL_URL}..."
nvm_echo "${TARBALL}"
return 0
fi
nvm_compare_checksum "${TARBALL}" "${CHECKSUM}"
nvm_err "Checksum check failed!"
nvm_err "Removing the broken local cache..."
command rm -rf "${TARBALL}"
fi
nvm_err "Downloading ${TARBALL_URL}..."
nvm_download -L -C - --progress-bar "${TARBALL_URL}" -o "${TARBALL}" || (
command rm -rf "${TARBALL}" "${tmpdir}"
nvm_err "Binary download from ${TARBALL_URL} failed, trying source."
@ -1753,7 +1762,6 @@ nvm_download_artifact() {
command rm -rf "${tmpdir}/files"
return 6
)
fi
nvm_echo "${TARBALL}"
}