From 836efe621fc842ee5b7ff1a42f9b8bcba5020a86 Mon Sep 17 00:00:00 2001 From: Bevan Kay Date: Mon, 5 Dec 2022 15:08:23 +1100 Subject: [PATCH] cask/artifiact/abstract_uninstall: allow wildcard entries for launchctl --- .../cask/artifact/abstract_uninstall.rb | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 15427c9e6f..50f4aab94a 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -95,14 +95,10 @@ module Cask # if launchctl item contains a wildcard, find matching process(es) services.each do |service| - all_services.push(service) - next unless /\*/.match?(service) + all_services << service + next unless service.include?("*") - find_launchctl_with_wildcard(service) - .map { |_, _, id| id } - .each do |match| - all_services.push(match) - end + all_services += find_launchctl_with_wildcard(service) end all_services.each do |service| @@ -284,13 +280,13 @@ module Cask end def find_launchctl_with_wildcard(search) + regex = Regexp.escape(search).gsub("\\*", ".*") system_command!("/bin/launchctl", args: ["list"]) .stdout.lines.drop(1) - .map { |line| line.chomp.split("\t") } - .map { |pid, state, id| [pid.to_i, state.to_i, id] } - .select do |(pid, _, id)| - pid.nonzero? && /\A#{Regexp.escape(search).gsub("\\*", ".*")}\Z/.match?(id) - end + .map do |line| + pid, _state, id = line.chomp.split("\t") + id if pid.to_i.nonzero? && id.match?(regex) + end.compact end # :kext should be unloaded before attempting to delete the relevant file