aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/installer.rb
diff options
context:
space:
mode:
authorMarkus Reiter2017-11-29 15:00:57 +0100
committerGitHub2017-11-29 15:00:57 +0100
commit3f7e63a24c7a449eeed3d5dcee1f209b924d58cb (patch)
treec9053c96df0826a03f3e80aaa3b141ba336d53fe /Library/Homebrew/cask/lib/hbc/installer.rb
parent6cf38d0dd87ab215bc5be13bf98f3654531b6ef4 (diff)
parent96187ade92c9ab222a5bc03aae96aa80ba80a6ae (diff)
downloadbrew-3f7e63a24c7a449eeed3d5dcee1f209b924d58cb.tar.bz2
Merge pull request #3492 from amyspark/fix-latest-casks
Properly upgrade Casks with version :latest
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/installer.rb')
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb46
1 files changed, 45 insertions, 1 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index b2087e643..8520f154d 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -360,16 +360,33 @@ module Hbc
disable_accessibility_access
uninstall_artifacts
+ backup
+ end
+
+ def backup
+ @cask.staged_path.rename backup_path
+ @cask.metadata_versioned_path.rename backup_metadata_path
+ end
+
+ def restore_backup
+ return unless backup_path.directory? && backup_metadata_path.directory?
+
+ Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist?
+ Pathname.new(@cask.metadata_versioned_path).rmtree if @cask.metadata_versioned_path.exist?
+
+ backup_path.rename @cask.staged_path
+ backup_metadata_path.rename @cask.metadata_versioned_path
end
def revert_upgrade
opoo "Reverting upgrade for Cask #{@cask}"
+ restore_backup
install_artifacts
enable_accessibility_access
end
def finalize_upgrade
- purge_versioned_files
+ purge_backed_up_versioned_files
puts summary
end
@@ -402,10 +419,37 @@ module Hbc
purge_caskroom_path
end
+ def backup_path
+ return nil if @cask.staged_path.nil?
+ Pathname.new "#{@cask.staged_path}.upgrading"
+ end
+
+ def backup_metadata_path
+ return nil if @cask.metadata_versioned_path.nil?
+ Pathname.new "#{@cask.metadata_versioned_path}.upgrading"
+ end
+
def gain_permissions_remove(path)
Utils.gain_permissions_remove(path, command: @command)
end
+ def purge_backed_up_versioned_files
+ ohai "Purging files for version #{@cask.version} of Cask #{@cask}"
+
+ # versioned staged distribution
+ gain_permissions_remove(backup_path) if !backup_path.nil? && backup_path.exist?
+
+ # Homebrew-Cask metadata
+ if backup_metadata_path.directory?
+ backup_metadata_path.children.each do |subdir|
+ unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename)
+ gain_permissions_remove(subdir)
+ end
+ end
+ end
+ backup_metadata_path.rmdir_if_possible
+ end
+
def purge_versioned_files
ohai "Purging files for version #{@cask.version} of Cask #{@cask}"