Skip to content

Commit

Permalink
attempt to clean up launchctl plists on uninstall
Browse files Browse the repository at this point in the history
separate `launchctl unload` and comment that this command was
intended for unloading jobs by pathname rather than bundle ID.
Leave that undocumented for now as it is untested.
  • Loading branch information
rolandwalker authored and jawshooah committed Jul 26, 2015
1 parent 9c4a1fa commit 5eec091
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
18 changes: 16 additions & 2 deletions lib/hbc/artifact/uninstall_base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'set'
require 'pathname'

class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base

Expand Down Expand Up @@ -210,9 +211,22 @@ def dispatch_uninstall_directives(stanza, expand_tilde=false)
[false, true].each do |with_sudo|
plist_status = @command.run('/bin/launchctl', :args => ['list', service], :sudo => with_sudo, :print_stderr => false).stdout
if %r{^\{}.match(plist_status)
@command.run('/bin/launchctl', :args => ['unload', '-w', '--', service], :sudo => with_sudo)
result = @command.run!('/bin/launchctl', :args => ['remove', service], :sudo => with_sudo)
if result.success?
paths = ["/Library/LaunchAgents/#{service}.plist",
"/Library/LaunchDaemons/#{service}.plist"]
paths.each { |elt| elt.prepend('~') } unless with_sudo
paths = paths.map { |elt| Pathname(elt) }.select(&:exist?)
paths.each do |path|
@command.run!('/bin/rm', :args => ['-f', '--', path], :sudo => with_sudo)
end
end
sleep 1
@command.run!('/bin/launchctl', :args => ['remove', service], :sudo => with_sudo)
end
# undocumented and untested: pass a path to uninstall :launchctl
if Pathname(service).exist?
@command.run!('/bin/launchctl', :args => ['unload', '-w', '--', service], :sudo => with_sudo)
@command.run!('/bin/rm', :args => ['-f', '--', service], :sudo => with_sudo)
sleep 1
end
end
Expand Down
1 change: 0 additions & 1 deletion test/cask/artifact/uninstall_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
)

Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/launchctl', 'remove', 'my.fancy.package.service'])
Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/launchctl', 'unload', '-w', '--', 'my.fancy.package.service'])

Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/sbin/kextstat', '-l', '-b', 'my.fancy.package.kernelextension'], 'loaded')
Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/sbin/kextunload', '-b', 'my.fancy.package.kernelextension'])
Expand Down
1 change: 0 additions & 1 deletion test/cask/artifact/zap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
)

Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/launchctl', 'remove', 'my.fancy.package.service'])
Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/launchctl', 'unload', '-w', '--', 'my.fancy.package.service'])

Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/sbin/kextstat', '-l', '-b', 'my.fancy.package.kernelextension'], 'loaded')
Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/sbin/kextunload', '-b', 'my.fancy.package.kernelextension'])
Expand Down

0 comments on commit 5eec091

Please sign in to comment.