Try #2 at handling backed up Casks
Avoid using variables altogether; fork out the purge into two specialized + one common function
This commit is contained in:
parent
9458e985b7
commit
9227c8fe3c
@ -29,7 +29,6 @@ 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?, :backed_up?
|
attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :upgrade?, :verbose?, :backed_up?
|
||||||
@ -383,7 +382,6 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def backup
|
def backup
|
||||||
@backed_up = true
|
|
||||||
@cask.staged_path.rename backup_path
|
@cask.staged_path.rename backup_path
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -393,7 +391,6 @@ module Hbc
|
|||||||
Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist?
|
Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist?
|
||||||
|
|
||||||
backup_path.rename @cask.staged_path
|
backup_path.rename @cask.staged_path
|
||||||
@backed_up = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def revert_upgrade
|
def revert_upgrade
|
||||||
@ -404,7 +401,7 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def finalize_upgrade
|
def finalize_upgrade
|
||||||
purge_versioned_files
|
purge_backed_versioned_files
|
||||||
|
|
||||||
puts summary
|
puts summary
|
||||||
end
|
end
|
||||||
@ -439,11 +436,7 @@ module Hbc
|
|||||||
|
|
||||||
def backup_path
|
def backup_path
|
||||||
return nil if @cask.staged_path.nil?
|
return nil if @cask.staged_path.nil?
|
||||||
if backed_up?
|
Pathname.new "#{@cask.staged_path}.upgrading"
|
||||||
Pathname.new "#{@cask.staged_path}.upgrading"
|
|
||||||
else
|
|
||||||
@cask.staged_path
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def version_is_latest?
|
def version_is_latest?
|
||||||
@ -454,19 +447,27 @@ module Hbc
|
|||||||
Utils.gain_permissions_remove(path, command: @command)
|
Utils.gain_permissions_remove(path, command: @command)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def purge_backed_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
|
||||||
|
purge_metadata
|
||||||
|
end
|
||||||
|
|
||||||
def purge_versioned_files
|
def purge_versioned_files
|
||||||
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?
|
gain_permissions_remove(@cask.staged_path) if !@cask.staged_path.nil? && @cask.staged_path.exist?
|
||||||
staged_path = backup_path
|
|
||||||
else
|
|
||||||
staged_path = @cask.staged_path
|
|
||||||
end
|
|
||||||
|
|
||||||
gain_permissions_remove(staged_path) if !staged_path.nil? && staged_path.exist?
|
|
||||||
|
|
||||||
# Homebrew-Cask metadata
|
# Homebrew-Cask metadata
|
||||||
|
purge_metadata
|
||||||
|
end
|
||||||
|
|
||||||
|
def purge_metadata
|
||||||
if @cask.metadata_versioned_path.respond_to?(:children) &&
|
if @cask.metadata_versioned_path.respond_to?(:children) &&
|
||||||
@cask.metadata_versioned_path.exist? &&
|
@cask.metadata_versioned_path.exist? &&
|
||||||
!(upgrade? && version_is_latest?)
|
!(upgrade? && version_is_latest?)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user