Skip to content
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
Expand Up @@ -4,6 +4,7 @@
require "timeout"

require "utils/user"
require "utils/uid"
require "cask/artifact/abstract_artifact"
require "cask/pkg"
require "extend/hash/keys"
Expand Down Expand Up @@ -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

View check run for this annotation

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
Expand Down Expand Up @@ -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

View check run for this annotation

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

View check run for this annotation

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

View check run for this annotation

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

View check run for this annotation

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|
Expand Down
Loading