Skip to content
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

Make bin/dist_get fall back to other downloaders if one fails #3692

Merged
merged 3 commits into from
Mar 2, 2017
Merged
Changes from 2 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
39 changes: 26 additions & 13 deletions bin/dist_get
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ check_writeable() {
printf "" > "$1" && rm "$1"
}

try_download() {
url="$1"
output="$2"
command="$3"
util_name=$(set -- $3; echo $1)
Copy link
Member

Choose a reason for hiding this comment

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

What is this doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This sets arguments within this shell substitution from $3, allowing us to get the first word of the command (wget, curl, http) with $1.
Arguments outside this shell substitution are not clobbered.

Copy link
Member

Choose a reason for hiding this comment

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

This might be reason it fails on circle, or other bashizm. CircleCI uses fsh as sh bin. You probably should change the hashbang to bash or remove the bashizm (preferably the latter)


if ! have_binary $util_name; then
return 1
fi

printf '==> Using %s to download "%s" to "%s"\n' "$util_name" "$url" "$output"
if eval "$command"; then
echo "==> Download complete!"
return
else
echo "error: couldn't download with $util_name ($?)"
return 1
fi
}

download() {
dl_url="$1"
dl_output="$2"
Expand All @@ -23,19 +43,12 @@ download() {
die "download error: cannot write to $dl_output"
fi

if have_binary wget; then
printf '==> Using wget to download "%s" to "%s"\n' "$dl_url" "$dl_output"
wget "$dl_url" -O "$dl_output" || return
elif have_binary curl; then
printf '==> Using curl to download "%s" to "%s"\n' "$dl_url" "$dl_output"
curl --silent "$dl_url" > "$dl_output" || return
elif have_binary fetch; then
printf '==> Using fetch to download "%s" to "%s"\n' "$dl_url" "$dl_output"
fetch "$dl_url" -o "$dl_output" || return
else
die "no binary found to download $dl_url. exiting."
fi
echo "==> download complete!"
try_download "$dl_url" "$dl_output" "wget '$dl_url' -O '$dl_output'" && return
try_download "$dl_url" "$dl_output" "curl --silent '$dl_url' > '$dl_output'" && return
try_download "$dl_url" "$dl_output" "fetch '$dl_url' -o '$dl_output'" && return
try_download "$dl_url" "$dl_output" "http '$dl_url' > '$dl_output'" && return

die "Unable to download $dl_url. exiting."
}

unarchive() {
Expand Down