From 9f7d86b97caf4c9448b19a7a400eb1ad44a8b81e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 12 Mar 2017 21:59:13 +0100 Subject: [PATCH] Add `#installed_caskfile` method to `Cask` class. --- Library/Homebrew/cask/lib/hbc/cask.rb | 5 +++++ Library/Homebrew/cask/lib/hbc/cli/list.rb | 3 +-- Library/Homebrew/cask/lib/hbc/cli/reinstall.rb | 12 +++--------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 975d69d074..8b39bdfd5e 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -84,6 +84,11 @@ module Hbc !versions.empty? end + def installed_caskfile + installed_version = timestamped_versions.last + metadata_master_container_path.join(*installed_version, "Casks", "#{token}.rb") + end + def to_s @token end diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 5d7a58b936..51ca5dabeb 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -36,8 +36,7 @@ module Hbc elsif @options[:versions] puts format_versioned(cask) else - installed_caskfile = cask.metadata_master_container_path.join(*cask.timestamped_versions.last, "Casks", "#{cask_token}.rb") - cask = Hbc.load(installed_caskfile) + cask = CaskLoader.load_from_file(cask.installed_caskfile) list_artifacts(cask) end diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb index 30d9b694c9..c101c9235d 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb @@ -17,16 +17,10 @@ module Hbc if cask.installed? # use copy of cask for uninstallation to avoid 'No such file or directory' bug installed_cask = cask - latest_installed_version = installed_cask.timestamped_versions.last - unless latest_installed_version.nil? - latest_installed_cask_file = installed_cask.metadata_master_container_path - .join(latest_installed_version - .join(File::Separator), - "Casks", "#{cask_token}.rb") - - # use the same cask file that was used for installation, if possible - installed_cask = CaskLoader.load_from_file(latest_installed_cask_file) if latest_installed_cask_file.exist? + # use the same cask file that was used for installation, if possible + if (installed_caskfile = installed_cask.installed_caskfile).exist? + installed_cask = CaskLoader.load_from_file(installed_caskfile) end # Always force uninstallation, ignore method parameter