Skip to content

rustup: Add option to skip download #21138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/etc/rustup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,33 @@ then
RUST_URL="${RUST_URL}/${CFG_DATE}"
fi

verify_hash() {
remote_sha256="$1"
local_file="$2"

download_hash() {
msg "Downloading ${remote_sha256}"
remote_sha256=`"${CFG_CURL}" -f "${remote_sha256}"`
if [ -n "${CFG_SAVE}" ]; then
echo "${remote_sha256}" > "${local_sha_file}"
fi
if [ "$?" -ne 0 ]; then
rm -Rf "${CFG_TMP_DIR}"
err "Failed to download ${remote_url}"
fi
}

verify_hash() {
remote_sha256="$1"
local_file="$2"
local_sha_file="${local_file}.sha256"

if [ -n "${CFG_SAVE}" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since download_hash already checks on "${CFG_SAVE}" I believe this could become:

if [ -f "${local_sha_file}" ]; then
    ....
else
    download_hash
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, currently download_hash can be called when ${CFG_SAVE} is both specified or not specified.
In case of specified, if file exists, we use that. If file doesn't exist, we download it to compare with, and save for future use.
In case ${CFG_SAVE} is specified, we download the file anyway and don't save it since it's not requested.
Simplifying to suggested variant would mean we check existence of saved file when ${CFG_SAVE} wasn't specified at all. I believe we shouldn't look at local files when saving wasn't requested.

if [ -f "${local_sha_file}" ]; then
msg "Local ${local_sha_file} exists, treating as remote hash"
remote_sha256=`cat "${local_sha_file}"`
else
download_hash
fi
else
download_hash
fi

msg "Verifying hash"
local_sha256=$(calculate_hash "${local_file}")
Expand Down