mirror of
https://github.com/Homebrew/brew.git
synced 2026-08-12 22:29:27 +04:00
Replace the API download retry loop with a single retry
Signed-off-by: Patrick Linnane <patrick@linnane.io>
This commit is contained in:
@@ -398,6 +398,21 @@ EOWARN
|
||||
trap - SIGINT
|
||||
}
|
||||
|
||||
api_curl_download() {
|
||||
local json_url="$1"
|
||||
local cache_path="$2"
|
||||
shift 2
|
||||
|
||||
curl \
|
||||
"${CURL_DISABLE_CURLRC_ARGS[@]}" \
|
||||
--fail --compressed --silent \
|
||||
--speed-limit "${HOMEBREW_CURL_SPEED_LIMIT}" --speed-time "${HOMEBREW_CURL_SPEED_TIME}" \
|
||||
--location --remote-time --output "${cache_path}" \
|
||||
"$@" \
|
||||
--user-agent "${HOMEBREW_USER_AGENT_CURL}" \
|
||||
"${json_url}"
|
||||
}
|
||||
|
||||
fetch_api_file() {
|
||||
local filename="$1"
|
||||
local update_failed_file="$2"
|
||||
@@ -436,23 +451,15 @@ fetch_api_file() {
|
||||
do
|
||||
time_cond+=("${arg}")
|
||||
done < <(api_time_cond_args "${cache_path}")
|
||||
while true
|
||||
do
|
||||
curl \
|
||||
"${CURL_DISABLE_CURLRC_ARGS[@]}" \
|
||||
--fail --compressed --silent \
|
||||
--speed-limit "${HOMEBREW_CURL_SPEED_LIMIT}" --speed-time "${HOMEBREW_CURL_SPEED_TIME}" \
|
||||
--location --remote-time --output "${cache_path}" \
|
||||
"${time_cond[@]}" \
|
||||
--user-agent "${HOMEBREW_USER_AGENT_CURL}" \
|
||||
"${json_url}"
|
||||
api_curl_download "${json_url}" "${cache_path}" "${time_cond[@]}"
|
||||
curl_exit_code=$?
|
||||
# A conditional request can fail with a receive error (curl exit code 56) when
|
||||
# an unconditional request for the same URL succeeds, so retry exactly once.
|
||||
if [[ ${curl_exit_code} -eq 56 ]] && [[ ${#time_cond[@]} -gt 0 ]]
|
||||
then
|
||||
api_curl_download "${json_url}" "${cache_path}"
|
||||
curl_exit_code=$?
|
||||
if [[ ${curl_exit_code} -ne 56 ]] || [[ ${#time_cond[@]} -eq 0 ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
time_cond=()
|
||||
done
|
||||
fi
|
||||
last_json_url="${json_url}"
|
||||
[[ ${curl_exit_code} -eq 0 ]] && break
|
||||
done < <(api_urls "${filename}")
|
||||
|
||||
Reference in New Issue
Block a user