From 36fe355159385669fbd5c294b901ed1df5bc745f Mon Sep 17 00:00:00 2001 From: L. E. Segovia Date: Sun, 12 Nov 2017 09:25:15 -0300 Subject: Add tests for upgrade recovery --- Library/Homebrew/cask/lib/hbc/cli/upgrade.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'Library/Homebrew/cask/lib') diff --git a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb index 90da6f325..94fe56a47 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb @@ -41,6 +41,9 @@ module Hbc require_sha: require_sha?, upgrade: true) + started_upgrade = false + new_artifacts_installed = false + begin # Start new Cask's installation steps new_cask_installer.check_conflicts @@ -51,9 +54,12 @@ module Hbc # Move the old Cask's artifacts back to staging old_cask_installer.start_upgrade + # And flag it so in case of error + started_upgrade = true # Install the new Cask new_cask_installer.install_artifacts + new_artifacts_installed = true new_cask_installer.enable_accessibility_access @@ -61,8 +67,9 @@ module Hbc old_cask_installer.finalize_upgrade rescue CaskError => e opoo e.message - new_cask_installer.uninstall - old_cask_installer.revert_upgrade + new_cask_installer.uninstall_artifacts if new_artifacts_installed + new_cask_installer.purge_versioned_files + old_cask_installer.revert_upgrade if started_upgrade end end end -- cgit v1.2.3