Merge pull request #6195 from reitermarkus/latest-cask-downloads

Don't redownload “latest” casks unnecessarily.
This commit is contained in:
Markus Reiter 2019-05-31 22:07:32 +02:00 committed by GitHub
commit eec2928754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 7 deletions

View File

@ -80,6 +80,13 @@ module Cask
!versions.empty? !versions.empty?
end end
def install_time
_, time = timestamped_versions.last
return unless time
Time.strptime(time, Metadata::TIMESTAMP_FORMAT)
end
def installed_caskfile def installed_caskfile
installed_version = timestamped_versions.last installed_version = timestamped_versions.last
metadata_master_container_path.join(*installed_version, "Casks", "#{token}.rb") metadata_master_container_path.join(*installed_version, "Casks", "#{token}.rb")

View File

@ -35,7 +35,7 @@ module Cask
attr_accessor :downloaded_path attr_accessor :downloaded_path
def clear_cache def clear_cache
downloader.clear_cache if force || cask.version.latest? downloader.clear_cache if force
end end
def fetch def fetch

View File

@ -3,6 +3,7 @@
module Cask module Cask
module Metadata module Metadata
METADATA_SUBDIR = ".metadata" METADATA_SUBDIR = ".metadata"
TIMESTAMP_FORMAT = "%Y%m%d%H%M%S.%L"
def metadata_master_container_path def metadata_master_container_path
@metadata_master_container_path ||= caskroom_path.join(METADATA_SUBDIR) @metadata_master_container_path ||= caskroom_path.join(METADATA_SUBDIR)
@ -58,12 +59,7 @@ module Cask
private private
def new_timestamp(time = Time.now) def new_timestamp(time = Time.now)
time = time.utc time.utc.strftime(TIMESTAMP_FORMAT)
timestamp = time.strftime("%Y%m%d%H%M%S")
fraction = format("%.3f", time.to_f - time.to_i)[1..-1]
timestamp.concat(fraction)
end end
end end
end end

View File

@ -296,6 +296,8 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
fresh = if cached_location.exist? && url_time fresh = if cached_location.exist? && url_time
url_time <= cached_location.mtime url_time <= cached_location.mtime
elsif version.respond_to?(:latest?)
!version.latest?
else else
true true
end end