提交 ea8e0f50 作者: Jeromy Johnson 提交者: GitHub

Merge pull request #3692 from mateon1/fix/dist-get

Make bin/dist_get fall back to other downloaders if one fails
...@@ -13,6 +13,26 @@ check_writeable() { ...@@ -13,6 +13,26 @@ check_writeable() {
printf "" > "$1" && rm "$1" printf "" > "$1" && rm "$1"
} }
try_download() {
url="$1"
output="$2"
command="$3"
util_name="$(set -- $command; echo "$1")"
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() { download() {
dl_url="$1" dl_url="$1"
dl_output="$2" dl_output="$2"
...@@ -23,19 +43,12 @@ download() { ...@@ -23,19 +43,12 @@ download() {
die "download error: cannot write to $dl_output" die "download error: cannot write to $dl_output"
fi fi
if have_binary wget; then try_download "$dl_url" "$dl_output" "wget '$dl_url' -O '$dl_output'" && return
printf '==> Using wget to download "%s" to "%s"\n' "$dl_url" "$dl_output" try_download "$dl_url" "$dl_output" "curl --silent '$dl_url' > '$dl_output'" && return
wget "$dl_url" -O "$dl_output" || return try_download "$dl_url" "$dl_output" "fetch '$dl_url' -o '$dl_output'" && return
elif have_binary curl; then try_download "$dl_url" "$dl_output" "http '$dl_url' > '$dl_output'" && return
printf '==> Using curl to download "%s" to "%s"\n' "$dl_url" "$dl_output"
curl --silent "$dl_url" > "$dl_output" || return die "Unable to download $dl_url. exiting."
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!"
} }
unarchive() { unarchive() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论