Check for range support instead of rescuing error.
This commit is contained in:
parent
34061628e6
commit
072127197a
@ -641,7 +641,7 @@ module Homebrew
|
||||
# We're in the cache; make sure to force re-download
|
||||
loop do
|
||||
begin
|
||||
curl_download url, continue_at: 0, to: filename
|
||||
curl_download url, to: filename
|
||||
break
|
||||
rescue
|
||||
if retry_count >= max_curl_retries
|
||||
|
@ -262,7 +262,7 @@ describe CurlDownloadStrategy do
|
||||
expect(subject).to receive(:curl).with(
|
||||
"--location",
|
||||
"--remote-time",
|
||||
"--continue-at", "-",
|
||||
"--continue-at", "0",
|
||||
"--output", an_instance_of(Pathname),
|
||||
url,
|
||||
an_instance_of(Hash)
|
||||
|
@ -46,21 +46,20 @@ def curl(*args)
|
||||
env: { "SSL_CERT_FILE" => nil }
|
||||
end
|
||||
|
||||
def curl_download(*args, to: nil, continue_at: "-", **options)
|
||||
def curl_download(*args, to: nil, **options)
|
||||
destination = Pathname(to)
|
||||
had_incomplete_download ||= destination.exist?
|
||||
destination.dirname.mkpath
|
||||
curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", destination, *args, **options)
|
||||
rescue ErrorDuringExecution => e
|
||||
# `curl` error 33: HTTP server doesn't seem to support byte ranges. Cannot resume.
|
||||
# HTTP status 416: Requested range not satisfiable
|
||||
if (e.status.exitstatus == 33 || had_incomplete_download) && continue_at == "-"
|
||||
continue_at = 0
|
||||
had_incomplete_download = false
|
||||
retry
|
||||
|
||||
continue_at = if destination.exist? &&
|
||||
curl_output("--location", "--head", "--range", "0-1",
|
||||
"--write-out", "%{http_code}",
|
||||
"--output", "/dev/null", *args, **options).stdout.to_i == 206 # Partial Content
|
||||
"-"
|
||||
else
|
||||
0
|
||||
end
|
||||
|
||||
raise
|
||||
curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", destination, *args, **options)
|
||||
end
|
||||
|
||||
def curl_output(*args, **options)
|
||||
|
Loading…
x
Reference in New Issue
Block a user