Let curl_download
handle HTTP 416 error.
This commit is contained in:
parent
914378cf2e
commit
1f66c9c9e0
@ -331,21 +331,11 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
if cached_location.exist?
|
if cached_location.exist?
|
||||||
puts "Already downloaded: #{cached_location}"
|
puts "Already downloaded: #{cached_location}"
|
||||||
else
|
else
|
||||||
had_incomplete_download = temporary_path.exist?
|
|
||||||
begin
|
begin
|
||||||
_fetch
|
_fetch
|
||||||
rescue ErrorDuringExecution
|
rescue ErrorDuringExecution
|
||||||
# 33 == range not supported
|
|
||||||
# try wiping the incomplete download and retrying once
|
|
||||||
unless $CHILD_STATUS.exitstatus == 33 && had_incomplete_download
|
|
||||||
raise CurlDownloadStrategyError, @url
|
raise CurlDownloadStrategyError, @url
|
||||||
end
|
end
|
||||||
|
|
||||||
ohai "Trying a full download"
|
|
||||||
temporary_path.unlink
|
|
||||||
had_incomplete_download = false
|
|
||||||
retry
|
|
||||||
end
|
|
||||||
ignore_interrupts { temporary_path.rename(cached_location) }
|
ignore_interrupts { temporary_path.rename(cached_location) }
|
||||||
end
|
end
|
||||||
rescue CurlDownloadStrategyError
|
rescue CurlDownloadStrategyError
|
||||||
|
@ -38,11 +38,14 @@ def curl(*args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def curl_download(*args, to: nil, continue_at: "-", **options)
|
def curl_download(*args, to: nil, continue_at: "-", **options)
|
||||||
|
had_incomplete_download ||= File.exist?(to)
|
||||||
curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", to, *args, **options)
|
curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", to, *args, **options)
|
||||||
rescue ErrorDuringExecution
|
rescue ErrorDuringExecution
|
||||||
# `curl` error 33: HTTP server doesn't seem to support byte ranges. Cannot resume.
|
# `curl` error 33: HTTP server doesn't seem to support byte ranges. Cannot resume.
|
||||||
if $CHILD_STATUS.exitstatus == 33 && continue_at == "-"
|
# HTTP status 416: Requested range not satisfiable
|
||||||
|
if ($CHILD_STATUS.exitstatus == 33 || had_incomplete_download) && continue_at == "-"
|
||||||
continue_at = 0
|
continue_at = 0
|
||||||
|
had_incomplete_download = false
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user