Skip to content

cask/uninstall: fix HOME references in uninstall stanzas for multi-user installs #19813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions Library/Homebrew/cask/artifact/abstract_uninstall.rb
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
require "timeout"

require "utils/user"
require "utils/uid"
require "cask/artifact/abstract_artifact"
require "cask/pkg"
require "extend/hash/keys"
@@ -74,7 +75,12 @@

args = directives[directive_sym]

send(:"uninstall_#{directive_sym}", *(args.is_a?(Hash) ? [args] : args), **options)
::Utils::UID.drop_euid do
env = { HOME: ::Utils::UID.uid_home }.compact
with_env(env) do

Check warning on line 80 in Library/Homebrew/cask/artifact/abstract_uninstall.rb

Codecov / codecov/patch

Library/Homebrew/cask/artifact/abstract_uninstall.rb#L78-L80

Added lines #L78 - L80 were not covered by tests
send(:"uninstall_#{directive_sym}", *(args.is_a?(Hash) ? [args] : args), **options)
end
end
end

def stanza
@@ -460,12 +466,23 @@
def trash_paths(*paths, command: nil, **_)
return if paths.empty?

# /usr/bin/trash is available only on macOS 15 or newer.
trashed_natively = if File.executable?("/usr/bin/trash")

Check warning on line 470 in Library/Homebrew/cask/artifact/abstract_uninstall.rb

Codecov / codecov/patch

Library/Homebrew/cask/artifact/abstract_uninstall.rb#L470

Added line #L470 was not covered by tests
system_command "/usr/bin/trash", args: paths
paths.reject(&:exist?)

Check warning on line 472 in Library/Homebrew/cask/artifact/abstract_uninstall.rb

Codecov / codecov/patch

Library/Homebrew/cask/artifact/abstract_uninstall.rb#L472

Added line #L472 was not covered by tests
else
[]
end

paths_to_trash = paths - trashed_natively

Check warning on line 477 in Library/Homebrew/cask/artifact/abstract_uninstall.rb

Codecov / codecov/patch

Library/Homebrew/cask/artifact/abstract_uninstall.rb#L477

Added line #L477 was not covered by tests
return trashed_natively, [] if paths_to_trash.empty?

stdout, = system_command HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift",
args: paths,
args: paths_to_trash,
print_stderr: Homebrew::EnvConfig.developer?

trashed, = stdout.partition("\n")
trashed = trashed.split(":") & paths
trashed = (trashed.split(":") + trashed_natively) & paths

Check warning on line 485 in Library/Homebrew/cask/artifact/abstract_uninstall.rb

Codecov / codecov/patch

Library/Homebrew/cask/artifact/abstract_uninstall.rb#L485

Added line #L485 was not covered by tests
untrashable = paths - trashed

trashed_with_permissions, untrashable = untrashable.partition do |path|
Loading
Oops, something went wrong.