aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorL. E. Segovia2017-11-28 13:00:08 +0000
committerL. E. Segovia2017-11-28 13:03:16 +0000
commitf3355b2a2c4a2128427af425efac1df5a336ba5e (patch)
treeb2e40a188f6f333182c1d56fdc3f29ab3e9025e5 /Library
parent10a0662dc013d7fd6949dce0a1bb75a1ec2bf91a (diff)
downloadbrew-f3355b2a2c4a2128427af425efac1df5a336ba5e.tar.bz2
Stage to a different directory if upgrading Casks w/version :latest
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/upgrade.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb32
2 files changed, 32 insertions, 4 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb
index bd80ad690..808b64c4b 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb
@@ -55,14 +55,14 @@ module Hbc
new_cask_installer.fetch
- new_cask_installer.stage
-
# 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.stage
+
new_cask_installer.install_artifacts
new_artifacts_installed = true
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index 6056250fc..84a8ac9b7 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -378,10 +378,26 @@ module Hbc
disable_accessibility_access
uninstall_artifacts
+ backup if version_is_latest?
+ end
+
+ def backup
+ @cask.staged_path.rename backup_path(@cask.staged_path)
+ end
+
+ def restore_backup
+ path = backup_path(@cask.staged_path)
+
+ return unless path.directory?
+
+ Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist?
+
+ path.rename @cask.staged_path
end
def revert_upgrade
opoo "Reverting upgrade for Cask #{@cask}"
+ restore_backup if version_is_latest?
install_artifacts
enable_accessibility_access
end
@@ -420,6 +436,14 @@ module Hbc
purge_caskroom_path
end
+ def backup_path(path)
+ Pathname.new "#{path}.upgrading" unless path.nil?
+ end
+
+ def version_is_latest?
+ @cask.versions.include?("latest")
+ end
+
def gain_permissions_remove(path)
Utils.gain_permissions_remove(path, command: @command)
end
@@ -428,11 +452,15 @@ module Hbc
ohai "Purging files for version #{@cask.version} of Cask #{@cask}"
# versioned staged distribution
- gain_permissions_remove(@cask.staged_path) if !@cask.staged_path.nil? && @cask.staged_path.exist?
+ staged_path = version_is_latest? ?
+ backup_path(@cask.staged_path) : @cask.staged_path
+
+ gain_permissions_remove(staged_path) if !staged_path.nil? && staged_path.exist?
# Homebrew-Cask metadata
if @cask.metadata_versioned_path.respond_to?(:children) &&
- @cask.metadata_versioned_path.exist?
+ @cask.metadata_versioned_path.exist? &&
+ !version_is_latest?
@cask.metadata_versioned_path.children.each do |subdir|
unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename)
gain_permissions_remove(subdir)