download with retry

This commit is contained in:
qudongfang
2018-08-20 20:09:26 +08:00
committed by Marco Vermeulen
parent fb820f2f8b
commit df6bdc278e
3 changed files with 25 additions and 4 deletions

View File

@@ -98,6 +98,15 @@ fi
if [[ -z "$sdkman_curl_connect_timeout" ]]; then sdkman_curl_connect_timeout=7; fi
if [[ -z "$sdkman_curl_max_time" ]]; then sdkman_curl_max_time=10; fi
# set curl retry
if [[ -z "${sdkman_curl_retry}" ]]; then sdkman_curl_retry=0; fi
# set curl retry max time in seconds
if [[ -z "${sdkman_curl_retry_max_time}" ]]; then sdkman_curl_retry_max_time=60; fi
# set curl to continue downloading automatically
if [[ -z "${sdkman_curl_continue_automatically}" ]]; then sdkman_curl_continue_automatically=true; fi
# Read list of candidates and set array
SDKMAN_CANDIDATES_CACHE="${SDKMAN_DIR}/var/candidates"
SDKMAN_CANDIDATES_CSV=$(<"$SDKMAN_CANDIDATES_CACHE")

View File

@@ -147,8 +147,8 @@ function __sdkman_download {
echo ""
#download binary
__sdkman_secure_curl_download "$download_url" > "$binary_input"
__sdkman_echo_debug "Downloaded binary to: $binary_input"
__sdkman_secure_curl_download "${download_url}" --output "${binary_input}"
__sdkman_echo_debug "Downloaded binary to: ${binary_input}"
#post-installation hook: implements function __sdkman_post_installation_hook
#responsible for taking `binary_input` and producing `zip_output`

View File

@@ -43,10 +43,22 @@ function __sdkman_secure_curl_download {
curl_params="$curl_params --cookie $cookie"
fi
if [[ ! -z "${sdkman_curl_retry}" ]]; then
curl_params="--retry ${sdkman_curl_retry} ${curl_params}"
fi
if [[ ! -z "${sdkman_curl_retry_max_time}" ]]; then
curl_params="--retry-max-time ${sdkman_curl_retry_max_time} ${curl_params}"
fi
if [[ "${sdkman_curl_continue_automatically}" == 'true' ]]; then
curl_params="-C - ${curl_params}"
fi
if [[ "$zsh_shell" == 'true' ]]; then
curl ${=curl_params} "$1"
curl ${=curl_params} "$@"
else
curl ${curl_params} "$1"
curl ${curl_params} "$@"
fi
}