Rework uninstallation step

Now the artifacts get re-staged, and upon an uninstall/finalize_upgrade
they are deleted by purge_versioned_files instead
This commit is contained in:
L. E. Segovia 2017-11-06 21:27:02 -03:00
parent 84c128411f
commit 94d266e2d6
2 changed files with 9 additions and 9 deletions

View File

@ -8,11 +8,11 @@ module Hbc
end end
def install_phase(**options) def install_phase(**options)
move(**options) move(source, target, **options)
end end
def uninstall_phase(**options) def uninstall_phase(**options)
delete(**options) move(target, source, **options)
end end
def summarize_installed def summarize_installed
@ -25,12 +25,12 @@ module Hbc
private private
def move(force: false, command: nil, **options) def move(source, target, force: false, command: nil, **options)
if Utils.path_occupied?(target) if Utils.path_occupied?(target)
message = "It seems there is already #{self.class.english_article} #{self.class.english_name} at '#{target}'" message = "It seems there is already #{self.class.english_article} #{self.class.english_name} at '#{target}'"
raise CaskError, "#{message}." unless force raise CaskError, "#{message}." unless force
opoo "#{message}; overwriting." opoo "#{message}; overwriting."
delete(force: force, command: command, **options) delete(target, force: force, command: command, **options)
end end
unless source.exist? unless source.exist?
@ -49,7 +49,7 @@ module Hbc
add_altname_metadata(target, source.basename, command: command) add_altname_metadata(target, source.basename, command: command)
end end
def delete(force: false, command: nil, **_) def delete(target, force: false, command: nil, **_)
ohai "Removing #{self.class.english_name} '#{target}'." ohai "Removing #{self.class.english_name} '#{target}'."
raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if MacOS.undeletable?(target) raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if MacOS.undeletable?(target)

View File

@ -136,7 +136,7 @@ module Hbc
def summary def summary
s = "" s = ""
s << "#{Emoji.install_badge} " if Emoji.enabled? s << "#{Emoji.install_badge} " if Emoji.enabled?
s << "#{@cask} was successfully installed!" s << "#{@cask} was successfully #{upgrade? ? "upgraded" : "installed"}!"
end end
def download def download
@ -384,13 +384,13 @@ module Hbc
def revert_upgrade def revert_upgrade
return unless upgrade? return unless upgrade?
opoo "Reverting upgrade for Cask #{@cask}" opoo "Reverting upgrade for Cask #{@cask}"
reinstall install_artifacts
enable_accessibility_access
end end
def finalize_upgrade def finalize_upgrade
return unless upgrade? return unless upgrade?
purge_versioned_files(upgrade: true) purge_versioned_files(upgrade: true)
oh1 "Cask #{@cask} was successfully upgraded!"
end end
def uninstall_artifacts def uninstall_artifacts
@ -426,7 +426,7 @@ module Hbc
end end
def purge_versioned_files(upgrade: false) def purge_versioned_files(upgrade: false)
odebug "Purging files for version #{@cask.version} of Cask #{@cask}" ohai "Purging files for version #{@cask.version} of Cask #{@cask}" unless upgrade?
# versioned staged distribution # versioned staged distribution
gain_permissions_remove(@cask.staged_path) if !@cask.staged_path.nil? && @cask.staged_path.exist? gain_permissions_remove(@cask.staged_path) if !@cask.staged_path.nil? && @cask.staged_path.exist?