recast uninstall_options as directives

This commit is contained in:
Roland Walker 2014-06-13 10:32:37 -04:00
parent 1e8bbd3c74
commit 077eecb731

View file

@ -86,8 +86,8 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base
directives_set = @cask.artifacts[stanza]
ohai "Running #{stanza} process for #{@cask}; your password may be necessary"
directives_set.each do |uninstall_options|
unknown_keys = uninstall_options.keys - [:early_script, :launchctl, :quit, :signal, :kext, :script, :pkgutil, :files]
directives_set.each do |directives|
unknown_keys = directives.keys - [:early_script, :launchctl, :quit, :signal, :kext, :script, :pkgutil, :files]
unless unknown_keys.empty?
opoo %Q{Unknown arguments to #{stanza}: #{unknown_keys.inspect}. Running "brew update && brew upgrade brew-cask && brew cleanup && brew cask cleanup" will likely fix it.}
end
@ -96,8 +96,8 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base
# Preserve prior functionality of script which runs first. Should rarely be needed.
# :early_script should not delete files, better defer that to :script.
# If Cask writers never need :early_script it may be removed in the future.
directives_set.select{ |h| h.key?(:early_script) }.each do |uninstall_options|
executable, script_arguments = self.class.read_script_arguments(uninstall_options, :early_script)
directives_set.select{ |h| h.key?(:early_script) }.each do |directives|
executable, script_arguments = self.class.read_script_arguments(directives, :early_script)
ohai "Running uninstall script #{executable}"
raise CaskInvalidError.new(@cask, "#{stanza} :early_script without :executable") if executable.nil?
@command.run(@cask.destination_path.join(executable), script_arguments)
@ -105,8 +105,8 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base
end
# :launchctl must come before :quit/:signal for cases where app would instantly re-launch
directives_set.select{ |h| h.key?(:launchctl) }.each do |uninstall_options|
Array(uninstall_options[:launchctl]).each do |service|
directives_set.select{ |h| h.key?(:launchctl) }.each do |directives|
Array(directives[:launchctl]).each do |service|
ohai "Removing launchctl service #{service}"
[false, true].each do |with_sudo|
xml_status = @command.run('/bin/launchctl', :args => ['list', '-x', service], :sudo => with_sudo)
@ -121,8 +121,8 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base
end
# :quit/:signal must come before :kext so the kext will not be in use by a running process
directives_set.select{ |h| h.key?(:quit) }.each do |uninstall_options|
Array(uninstall_options[:quit]).each do |id|
directives_set.select{ |h| h.key?(:quit) }.each do |directives|
Array(directives[:quit]).each do |id|
ohai "Quitting application ID #{id}"
num_running = @command.run!('/usr/bin/osascript', :args => ['-e', %Q{tell application "System Events" to count processes whose bundle identifier is "#{id}"}], :sudo => true).to_i
if num_running > 0
@ -133,8 +133,8 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base
end
# :signal should come after :quit so it can be used as a backup when :quit fails
directives_set.select{ |h| h.key?(:signal) }.each do |uninstall_options|
Array(uninstall_options[:signal]).flatten.each_slice(2) do |pair|
directives_set.select{ |h| h.key?(:signal) }.each do |directives|
Array(directives[:signal]).flatten.each_slice(2) do |pair|
raise CaskInvalidError.new(@cask, "Each #{stanza} :signal must have 2 elements.") unless pair.length == 2
signal, id = pair
ohai "Signalling '#{signal}' to application ID '#{id}'"
@ -157,8 +157,8 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base
end
# :kext should be unloaded before attempting to delete the relevant file
directives_set.select{ |h| h.key?(:kext) }.each do |uninstall_options|
Array(uninstall_options[:kext]).each do |kext|
directives_set.select{ |h| h.key?(:kext) }.each do |directives|
Array(directives[:kext]).each do |kext|
ohai "Unloading kernel extension #{kext}"
is_loaded = @command.run!('/usr/sbin/kextstat', :args => ['-l', '-b', kext], :sudo => true)
if is_loaded.length > 1
@ -169,23 +169,23 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base
end
# :script must come before :pkgutil or :files so that the script file is not already deleted
directives_set.select{ |h| h.key?(:script) }.each do |uninstall_options|
executable, script_arguments = self.class.read_script_arguments(uninstall_options, :script)
directives_set.select{ |h| h.key?(:script) }.each do |directives|
executable, script_arguments = self.class.read_script_arguments(directives, :script)
raise CaskInvalidError.new(@cask, "#{stanza} :script without :executable.") if executable.nil?
@command.run(@cask.destination_path.join(executable), script_arguments)
sleep 1
end
directives_set.select{ |h| h.key?(:pkgutil) }.each do |uninstall_options|
directives_set.select{ |h| h.key?(:pkgutil) }.each do |directives|
ohai "Removing files from pkgutil Bill-of-Materials"
Array(uninstall_options[:pkgutil]).each do |regexp|
Array(directives[:pkgutil]).each do |regexp|
pkgs = Cask::Pkg.all_matching(regexp, @command)
pkgs.each(&:uninstall)
end
end
directives_set.select{ |h| h.key?(:files) }.each do |uninstall_options|
Array(uninstall_options[:files]).flatten.each_slice(500) do |file_slice|
directives_set.select{ |h| h.key?(:files) }.each do |directives|
Array(directives[:files]).flatten.each_slice(500) do |file_slice|
ohai "Removing files: #{file_slice.utf8_inspect}"
@command.run!('/bin/rm', :args => file_slice.unshift('-rf', '--'), :sudo => true)
end