Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Added retry function to resume partial downloads. #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 19 additions & 4 deletions rustup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ download_checksum_for() {
verbose_say "download work dir: $_workdir"

verbose_say "downloading '$_remote_sums' to '$_workdir'"
(run cd "$_workdir" && run curl -s -f -O "$_remote_sums")
(run cd "$_workdir" && retry curl -s -f -O "$_remote_sums")
if [ $? != 0 ]; then
say_err "couldn't download checksum file '$_remote_sums'"
ignore rm -R "$_workdir"
Expand Down Expand Up @@ -1777,7 +1777,7 @@ download_file_and_sig() {
fi

verbose_say "downloading '$_remote_sig' to '$_local_sig'"
(run cd "$_local_dirname" && run curl -s -C - -f -O "$_remote_sig")
(run cd "$_local_dirname" && retry curl -s -C - -f -O "$_remote_sig")
if [ $? != 0 ]; then
say_err "couldn't download signature file '$_remote_sig'"
return 1
Expand All @@ -1796,9 +1796,9 @@ download_file_and_sig() {
verbose_say "downloading '$_remote_name' to '$_local_name'"
# Invoke curl in a way that will resume if necessary
if [ "$_quiet" = false ]; then
(run cd "$_local_dirname" && run curl -# -C - -f -O "$_remote_name")
(run cd "$_local_dirname" && retry curl -# -C - -f -O "$_remote_name")
else
(run cd "$_local_dirname" && run curl -s -C - -f -O "$_remote_name")
(run cd "$_local_dirname" && retry curl -s -C - -f -O "$_remote_name")
fi
if [ $? != 0 ]; then
say_err "couldn't download '$_remote_name'"
Expand Down Expand Up @@ -1948,6 +1948,21 @@ ignore() {
run "$@"
}

# Runs a command and tries again until it succeeds.
# Use this for network downloads to handle temporary errors.
retry() {
until "$@"
do
say "command failed, retrying: $*"
sleep 0.5 # rate limit (2 per second)
done
local _retval="$?"
if [ $_retval != 0 ]; then # only happens if user aborts
say_err "command failed: $*"
fi
return $_retval
}

# Runs a command and prints it to stderr if it fails.
run() {
"$@"
Expand Down