Check if cached downloads are up-to-date.
This commit is contained in:
parent
b9b6e3b9c0
commit
3d805295eb
@ -287,12 +287,18 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
|
|
||||||
ohai "Downloading #{url}"
|
ohai "Downloading #{url}"
|
||||||
|
|
||||||
if cached_location.exist?
|
resolved_url, _, url_time = resolve_url_basename_time(url)
|
||||||
|
|
||||||
|
fresh = if cached_location.exist? && url_time
|
||||||
|
url_time <= cached_location.mtime
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
if cached_location.exist? && fresh
|
||||||
puts "Already downloaded: #{cached_location}"
|
puts "Already downloaded: #{cached_location}"
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
resolved_url, = resolve_url_and_basename(url)
|
|
||||||
|
|
||||||
_fetch(url: url, resolved_url: resolved_url)
|
_fetch(url: url, resolved_url: resolved_url)
|
||||||
rescue ErrorDuringExecution
|
rescue ErrorDuringExecution
|
||||||
raise CurlDownloadStrategyError, url
|
raise CurlDownloadStrategyError, url
|
||||||
@ -324,11 +330,11 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
|
|
||||||
def resolved_url_and_basename
|
def resolved_url_and_basename
|
||||||
return @resolved_url_and_basename if defined?(@resolved_url_and_basename)
|
return @resolved_url_and_basename if defined?(@resolved_url_and_basename)
|
||||||
|
resolved_url, basename, = resolve_url_basename_time(url)
|
||||||
@resolved_url_and_basename = resolve_url_and_basename(url)
|
@resolved_url_and_basename = [resolved_url, basename]
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_url_and_basename(url)
|
def resolve_url_basename_time(url)
|
||||||
if ENV["HOMEBREW_ARTIFACT_DOMAIN"]
|
if ENV["HOMEBREW_ARTIFACT_DOMAIN"]
|
||||||
url = url.sub(%r{^((ht|f)tps?://)?}, ENV["HOMEBREW_ARTIFACT_DOMAIN"].chomp("/") + "/")
|
url = url.sub(%r{^((ht|f)tps?://)?}, ENV["HOMEBREW_ARTIFACT_DOMAIN"].chomp("/") + "/")
|
||||||
end
|
end
|
||||||
@ -356,9 +362,15 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
lines.map { |line| line[/^Content\-Disposition:\s*(?:inline|attachment);\s*filename=(["']?)([^;]+)\1/i, 2] }
|
lines.map { |line| line[/^Content\-Disposition:\s*(?:inline|attachment);\s*filename=(["']?)([^;]+)\1/i, 2] }
|
||||||
.compact
|
.compact
|
||||||
|
|
||||||
|
time =
|
||||||
|
lines.map { |line| line[/^Last\-Modified:\s*(.+)/i, 1] }
|
||||||
|
.compact
|
||||||
|
.map(&Time.public_method(:parse))
|
||||||
|
.last
|
||||||
|
|
||||||
basename = filenames.last || parse_basename(redirect_url)
|
basename = filenames.last || parse_basename(redirect_url)
|
||||||
|
|
||||||
[redirect_url, basename]
|
[redirect_url, basename, time]
|
||||||
end
|
end
|
||||||
|
|
||||||
def _fetch(url:, resolved_url:)
|
def _fetch(url:, resolved_url:)
|
||||||
@ -419,12 +431,9 @@ class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def resolve_url_and_basename(url)
|
def resolve_url_basename_time(url)
|
||||||
if url == self.url
|
if url == self.url
|
||||||
[
|
super("#{apache_mirrors["preferred"]}#{apache_mirrors["path_info"]}")
|
||||||
"#{apache_mirrors["preferred"]}#{apache_mirrors["path_info"]}",
|
|
||||||
File.basename(apache_mirrors["path_info"]),
|
|
||||||
]
|
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user