diff options
| author | L. E. Segovia | 2017-10-30 23:29:00 -0300 |
|---|---|---|
| committer | L. E. Segovia | 2017-10-30 23:29:00 -0300 |
| commit | 7f2e4f583a5789a86712322818612c439307b90d (patch) | |
| tree | 12b55d84f1dea61ee7b750823754a98b7c7c0fb8 /Library | |
| parent | 55727b789532fbfa7997929aa0506d7843eda3ce (diff) | |
| download | brew-7f2e4f583a5789a86712322818612c439307b90d.tar.bz2 | |
Finalize metadata handling and uninstall logic
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/upgrade.rb | 24 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/installer.rb | 31 |
2 files changed, 35 insertions, 20 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb index 49a538704..e68fc4e53 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb @@ -34,25 +34,29 @@ module Hbc old_cask_installer = Installer.new(old_cask, binaries: binaries?, verbose: verbose?, force: force?, upgrade: true) - old_cask_installer.uninstall - - begin - odebug "Installing new version of Cask #{old_cask}" - - new_cask = CaskLoader.load(old_cask.to_s) + new_cask = CaskLoader.load(old_cask.to_s) + new_cask_installer = Installer.new(new_cask, binaries: binaries?, verbose: verbose?, force: force?, skip_cask_deps: skip_cask_deps?, require_sha: require_sha?, - upgrade: true).install + upgrade: true) + + begin + # purge artifacts BUT keep metadata aside + old_cask_installer.start_upgrade + + # install BUT do not yet save metadata + new_cask_installer.install + + # if successful, remove old metadata and install new old_cask_installer.finalize_upgrade - rescue CaskUnavailableError => e - opoo e.message - rescue CaskAlreadyInstalledError => e + rescue CaskError => e opoo e.message + old_cask_installer.revert_upgrade end end end diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 629a20f31..80dd2ca4c 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -83,8 +83,8 @@ module Hbc def install odebug "Hbc::Installer#install" - if @cask.installed? && !force? && !@reinstall && !@upgrade - raise CaskAlreadyInstalledError, @cask + if @cask.installed? && !force? && !@reinstall + raise CaskAlreadyInstalledError, @cask unless @upgrade end check_conflicts @@ -369,17 +369,28 @@ module Hbc oh1 "Uninstalling Cask #{@cask}" disable_accessibility_access uninstall_artifacts - return if @upgrade - purge_versioned_files purge_caskroom_path if force? end - def finalize_upgrade + def start_upgrade return unless @upgrade + oh1 "Starting upgrade for Cask #{@cask}" - purge_versioned_files - purge_caskroom_path if force? + disable_accessibility_access + uninstall_artifacts + end + + def revert_upgrade + return unless @upgrade + opoo "Reverting upgrade for Cask #{@cask}" + reinstall + end + + def finalize_upgrade + return unless @upgrade + purge_versioned_files(upgrade: true) + oh1 "Cask #{@cask} was successfully upgraded!" end def uninstall_artifacts @@ -414,7 +425,7 @@ module Hbc Utils.gain_permissions_remove(path, command: @command) end - def purge_versioned_files + def purge_versioned_files(upgrade: false) odebug "Purging files for version #{@cask.version} of Cask #{@cask}" # versioned staged distribution @@ -430,10 +441,10 @@ module Hbc end end @cask.metadata_versioned_path.rmdir_if_possible - @cask.metadata_master_container_path.rmdir_if_possible + @cask.metadata_master_container_path.rmdir_if_possible unless upgrade # toplevel staged distribution - @cask.caskroom_path.rmdir_if_possible + @cask.caskroom_path.rmdir_if_possible unless upgrade end def purge_caskroom_path |
