Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't redownload “latest” casks unnecessarily. #6195

Merged
merged 2 commits into from May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Library/Homebrew/cask/cask.rb
Expand Up @@ -80,6 +80,13 @@ def installed?
!versions.empty?
end

def install_time
_, time = timestamped_versions.last
return unless time

Time.strptime(time, Metadata::TIMESTAMP_FORMAT)
end

def installed_caskfile
installed_version = timestamped_versions.last
metadata_master_container_path.join(*installed_version, "Casks", "#{token}.rb")
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/download.rb
Expand Up @@ -35,7 +35,7 @@ def downloader
attr_accessor :downloaded_path

def clear_cache
downloader.clear_cache if force || cask.version.latest?
downloader.clear_cache if force
end

def fetch
Expand Down
8 changes: 2 additions & 6 deletions Library/Homebrew/cask/metadata.rb
Expand Up @@ -3,6 +3,7 @@
module Cask
module Metadata
METADATA_SUBDIR = ".metadata"
TIMESTAMP_FORMAT = "%Y%m%d%H%M%S.%L"

def metadata_master_container_path
@metadata_master_container_path ||= caskroom_path.join(METADATA_SUBDIR)
Expand Down Expand Up @@ -58,12 +59,7 @@ def metadata_subdir(leaf, version: self.version, timestamp: :latest, create: fal
private

def new_timestamp(time = Time.now)
time = time.utc

timestamp = time.strftime("%Y%m%d%H%M%S")
fraction = format("%.3f", time.to_f - time.to_i)[1..-1]

timestamp.concat(fraction)
time.utc.strftime(TIMESTAMP_FORMAT)
end
end
end
2 changes: 2 additions & 0 deletions Library/Homebrew/download_strategy.rb
Expand Up @@ -296,6 +296,8 @@ def fetch

fresh = if cached_location.exist? && url_time
url_time <= cached_location.mtime
elsif version.respond_to?(:latest?)
!version.latest?
else
true
end
Expand Down