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