From 367fdb971839c0b3686ca23a6de76da75cc80580 Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Sat, 18 Mar 2017 17:48:20 -0500 Subject: Refactor brew cask reinstall The implementation of the reinstall command was the same as Installer#install, aside from the uninstall of the existing cask. Moved this within the class to DRY up the implementation. --- Library/Homebrew/cask/lib/hbc/cli/reinstall.rb | 29 +++++--------------------- Library/Homebrew/cask/lib/hbc/installer.rb | 19 +++++++++++++++-- 2 files changed, 22 insertions(+), 26 deletions(-) (limited to 'Library/Homebrew/cask') diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb index b52c43328..c27fa9f2f 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb @@ -7,30 +7,11 @@ module Hbc begin cask = CaskLoader.load(cask_token) - installer = Installer.new(cask, - force: force, - skip_cask_deps: skip_cask_deps, - require_sha: require_sha) - installer.print_caveats - installer.fetch - - if cask.installed? - # use copy of cask for uninstallation to avoid 'No such file or directory' bug - installed_cask = cask - - # 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 - Installer.new(installed_cask, force: true).uninstall - end - - installer.stage - installer.install_artifacts - installer.enable_accessibility_access - puts installer.summary + Installer.new(cask, + force: force, + skip_cask_deps: skip_cask_deps, + require_sha: require_sha, + reinstall: true).install count += 1 rescue CaskUnavailableError => e diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 824c1b1be..6f6957574 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -18,12 +18,13 @@ module Hbc PERSISTENT_METADATA_SUBDIRS = ["gpg"].freeze - def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, require_sha: false) + def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, require_sha: false, reinstall: false) @cask = cask @command = command @force = force @skip_cask_deps = skip_cask_deps @require_sha = require_sha + @reinstall = reinstall end def self.print_caveats(cask) @@ -76,13 +77,14 @@ module Hbc def install odebug "Hbc::Installer#install" - if @cask.installed? && !force + if @cask.installed? && !force && !@reinstall raise CaskAlreadyInstalledAutoUpdatesError, @cask if @cask.auto_updates raise CaskAlreadyInstalledError, @cask end print_caveats fetch + uninstall_if_neccessary stage install_artifacts enable_accessibility_access @@ -90,6 +92,19 @@ module Hbc puts summary end + def uninstall_if_neccessary + return unless @cask.installed? && @reinstall + installed_cask = @cask + + # 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 + Installer.new(installed_cask, force: true).uninstall + end + def summary s = "" s << "#{Emoji.install_badge} " if Emoji.enabled? -- cgit v1.2.3 From 3703ef1885ba4afce1ed4ae531dcb7ddc573b3c2 Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Sat, 18 Mar 2017 18:57:04 -0500 Subject: Show messages when (un)installing Casks Addresses an issue where it can be unclear at times exactly which part of the (un|re)installation processes is reporting an error. See https://github.com/caskroom/homebrew-cask/issues/30968 --- Library/Homebrew/cask/lib/hbc/installer.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew/cask') diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 6f6957574..69113e9fc 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -85,6 +85,8 @@ module Hbc print_caveats fetch uninstall_if_neccessary + + oh1 "Installing Cask #{@cask}" stage install_artifacts enable_accessibility_access @@ -322,7 +324,7 @@ module Hbc end def uninstall - odebug "Hbc::Installer#uninstall" + oh1 "Uninstalling Cask #{@cask}" disable_accessibility_access uninstall_artifacts purge_versioned_files -- cgit v1.2.3 From a90d1e169939cea7006f7465fe8c04370005223d Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Mon, 27 Mar 2017 01:31:29 -0500 Subject: Installer#reinstall instead of #install :reinstall Call an explicit method on Installer to reinstall rather than using a flag to indicate when we're reinstalling a cask --- Library/Homebrew/cask/lib/hbc/cli/reinstall.rb | 3 +-- Library/Homebrew/cask/lib/hbc/installer.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'Library/Homebrew/cask') diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb index c27fa9f2f..c2ed8f462 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb @@ -10,8 +10,7 @@ module Hbc Installer.new(cask, force: force, skip_cask_deps: skip_cask_deps, - require_sha: require_sha, - reinstall: true).install + require_sha: require_sha).reinstall count += 1 rescue CaskUnavailableError => e diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 69113e9fc..c9b6b4e53 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -18,13 +18,13 @@ module Hbc PERSISTENT_METADATA_SUBDIRS = ["gpg"].freeze - def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, require_sha: false, reinstall: false) + def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, require_sha: false) @cask = cask @command = command @force = force @skip_cask_deps = skip_cask_deps @require_sha = require_sha - @reinstall = reinstall + @reinstall = false end def self.print_caveats(cask) @@ -94,6 +94,12 @@ module Hbc puts summary end + def reinstall + odebug "Hbc::Installer#reinstall" + @reinstall = true + install + end + def uninstall_if_neccessary return unless @cask.installed? && @reinstall installed_cask = @cask -- cgit v1.2.3 From cb28ab640e191500d480308ca262366184518022 Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Mon, 17 Apr 2017 17:21:02 -0700 Subject: Refactor uninstall existing cask --- Library/Homebrew/cask/lib/hbc/installer.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'Library/Homebrew/cask') diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index c9b6b4e53..51b0490f5 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -84,7 +84,7 @@ module Hbc print_caveats fetch - uninstall_if_neccessary + uninstall_existing_cask if @reinstall oh1 "Installing Cask #{@cask}" stage @@ -100,14 +100,12 @@ module Hbc install end - def uninstall_if_neccessary - return unless @cask.installed? && @reinstall - installed_cask = @cask + def uninstall_existing_cask + return unless @cask.installed? # 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 + installed_caskfile = @cask.installed_caskfile + installed_cask = installed_caskfile.exist? ? CaskLoader.load_from_file(installed_caskfile) : @cask # Always force uninstallation, ignore method parameter Installer.new(installed_cask, force: true).uninstall -- cgit v1.2.3