From b12623f4eb9666003a8bb915a73ee6d621c81465 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 31 May 2019 20:37:57 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Don't=20redownload=20=E2=80=9Clatest?= =?UTF-8?q?=E2=80=9D=20casks=20unnecessarily.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/cask/download.rb | 2 +- Library/Homebrew/download_strategy.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/download.rb b/Library/Homebrew/cask/download.rb index eb3a444bc4e9b..4bd4e4426a77d 100644 --- a/Library/Homebrew/cask/download.rb +++ b/Library/Homebrew/cask/download.rb @@ -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 diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 5afb8c13ede92..924c17f117456 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -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 From 17f6d19b9c178b2d54abcea67c5eba22b619588f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 31 May 2019 20:38:28 +0200 Subject: [PATCH 2/2] Add `Cask#install_time` method. --- Library/Homebrew/cask/cask.rb | 7 +++++++ Library/Homebrew/cask/metadata.rb | 8 ++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 23d20dcc7889f..aef26e8b6f39f 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -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") diff --git a/Library/Homebrew/cask/metadata.rb b/Library/Homebrew/cask/metadata.rb index 9a47567e9f570..b15fbdda394aa 100644 --- a/Library/Homebrew/cask/metadata.rb +++ b/Library/Homebrew/cask/metadata.rb @@ -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) @@ -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