aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorL. E. Segovia2017-11-28 17:37:36 +0000
committerL. E. Segovia2017-11-28 17:37:36 +0000
commit9458e985b79d4c9fca78ed0beab07a5c72d31c3e (patch)
treefe98fce3f7d5124963fc928926d3c4472c2edb89 /Library/Homebrew
parent2ff114bc32ce677ed133ea805e4686214aaf8153 (diff)
downloadbrew-9458e985b79d4c9fca78ed0beab07a5c72d31c3e.tar.bz2
Always backup the old Cask prior to upgrade
(and if doing so, correctly set the staged_path when purging it)
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb30
1 files changed, 18 insertions, 12 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index 30d5f30be..ca13f7eed 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -29,9 +29,10 @@ module Hbc
@require_sha = require_sha
@reinstall = false
@upgrade = upgrade
+ @backed_up = false
end
- attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :upgrade?, :verbose?
+ attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :upgrade?, :verbose?, :backed_up?
def self.print_caveats(cask)
odebug "Printing caveats"
@@ -378,26 +379,26 @@ module Hbc
disable_accessibility_access
uninstall_artifacts
- backup if version_is_latest?
+ backup
end
def backup
- @cask.staged_path.rename backup_path(@cask.staged_path)
+ @backed_up = true
+ @cask.staged_path.rename backup_path
end
def restore_backup
- path = backup_path(@cask.staged_path)
-
- return unless path.directory?
+ return unless backup_path.directory?
Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist?
- path.rename @cask.staged_path
+ backup_path.rename @cask.staged_path
+ @backed_up = false
end
def revert_upgrade
opoo "Reverting upgrade for Cask #{@cask}"
- restore_backup if version_is_latest?
+ restore_backup
install_artifacts
enable_accessibility_access
end
@@ -436,8 +437,13 @@ module Hbc
purge_caskroom_path
end
- def backup_path(path)
- Pathname.new "#{path}.upgrading" unless path.nil?
+ def backup_path
+ return nil if @cask.staged_path.nil?
+ if backed_up?
+ Pathname.new "#{@cask.staged_path}.upgrading"
+ else
+ @cask.staged_path
+ end
end
def version_is_latest?
@@ -452,8 +458,8 @@ module Hbc
ohai "Purging files for version #{@cask.version} of Cask #{@cask}"
# versioned staged distribution
- if upgrade? && version_is_latest?
- staged_path = backup_path(@cask.staged_path)
+ if upgrade?
+ staged_path = backup_path
else
staged_path = @cask.staged_path
end