diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index 1cc3231627..f9e3582b30 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -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 diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index 012370b70e..71385c7f58 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -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) diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 2856012bbe..40e8f26380 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -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)