Always backup the old Cask prior to upgrade
(and if doing so, correctly set the staged_path when purging it)
This commit is contained in:
parent
2ff114bc32
commit
9458e985b7
@ -29,9 +29,10 @@ module Hbc
|
|||||||
@require_sha = require_sha
|
@require_sha = require_sha
|
||||||
@reinstall = false
|
@reinstall = false
|
||||||
@upgrade = upgrade
|
@upgrade = upgrade
|
||||||
|
@backed_up = false
|
||||||
end
|
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)
|
def self.print_caveats(cask)
|
||||||
odebug "Printing caveats"
|
odebug "Printing caveats"
|
||||||
@ -378,26 +379,26 @@ module Hbc
|
|||||||
|
|
||||||
disable_accessibility_access
|
disable_accessibility_access
|
||||||
uninstall_artifacts
|
uninstall_artifacts
|
||||||
backup if version_is_latest?
|
backup
|
||||||
end
|
end
|
||||||
|
|
||||||
def backup
|
def backup
|
||||||
@cask.staged_path.rename backup_path(@cask.staged_path)
|
@backed_up = true
|
||||||
|
@cask.staged_path.rename backup_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def restore_backup
|
def restore_backup
|
||||||
path = backup_path(@cask.staged_path)
|
return unless backup_path.directory?
|
||||||
|
|
||||||
return unless path.directory?
|
|
||||||
|
|
||||||
Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist?
|
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
|
end
|
||||||
|
|
||||||
def revert_upgrade
|
def revert_upgrade
|
||||||
opoo "Reverting upgrade for Cask #{@cask}"
|
opoo "Reverting upgrade for Cask #{@cask}"
|
||||||
restore_backup if version_is_latest?
|
restore_backup
|
||||||
install_artifacts
|
install_artifacts
|
||||||
enable_accessibility_access
|
enable_accessibility_access
|
||||||
end
|
end
|
||||||
@ -436,8 +437,13 @@ module Hbc
|
|||||||
purge_caskroom_path
|
purge_caskroom_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def backup_path(path)
|
def backup_path
|
||||||
Pathname.new "#{path}.upgrading" unless path.nil?
|
return nil if @cask.staged_path.nil?
|
||||||
|
if backed_up?
|
||||||
|
Pathname.new "#{@cask.staged_path}.upgrading"
|
||||||
|
else
|
||||||
|
@cask.staged_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def version_is_latest?
|
def version_is_latest?
|
||||||
@ -452,8 +458,8 @@ module Hbc
|
|||||||
ohai "Purging files for version #{@cask.version} of Cask #{@cask}"
|
ohai "Purging files for version #{@cask.version} of Cask #{@cask}"
|
||||||
|
|
||||||
# versioned staged distribution
|
# versioned staged distribution
|
||||||
if upgrade? && version_is_latest?
|
if upgrade?
|
||||||
staged_path = backup_path(@cask.staged_path)
|
staged_path = backup_path
|
||||||
else
|
else
|
||||||
staged_path = @cask.staged_path
|
staged_path = @cask.staged_path
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user