Skip to content

Commit

Permalink
Improve nvm_download_artifact() process, fix nvm-sh#1291
Browse files Browse the repository at this point in the history
 - Delete broken/checksum not matched local cache
 - More output message.
  • Loading branch information
PeterDaveHello committed Nov 10, 2016
1 parent 9c92b5a commit f9dc1e0
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1725,28 +1725,37 @@ nvm_download_artifact() {
TARBALL_URL="${MIRROR}/${SLUG}.tar.${COMPRESSION}"
fi

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_download -L -C - --progress-bar "${TARBALL_URL}" -o "${TARBALL}" || (
command rm -rf "${TARBALL}" "${tmpdir}"
nvm_err "Binary download from ${TARBALL_URL} failed, trying source."
return 4
)

if nvm_grep '404 Not Found' "${TARBALL}" >/dev/null; then
command rm -rf "${TARBALL}" "$tmpdir"
nvm_err "HTTP 404 at URL ${TARBALL_URL}";
return 5
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}")"
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}"
nvm_err "Downloading ${TARBALL_URL} ..."
fi
nvm_echo "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."
return 4
)

nvm_compare_checksum "${TARBALL}" "${CHECKSUM}" || (
command rm -rf "${tmpdir}/files"
return 6
)
if nvm_grep '404 Not Found' "${TARBALL}" >/dev/null; then
command rm -rf "${TARBALL}" "$tmpdir"
nvm_err "HTTP 404 at URL ${TARBALL_URL}";
return 5
fi

nvm_compare_checksum "${TARBALL}" "${CHECKSUM}" || (
command rm -rf "${tmpdir}/files"
return 6
)

nvm_echo "${TARBALL}"
}

Expand Down

0 comments on commit f9dc1e0

Please sign in to comment.