cask/artifact/abstract_uninstall: handle sudo trashed paths correctly

This showed a confusing message when the trash path was able to be
deleted using sudo since the untrashable array was updated but
the check was higher up for returning early.

```
==> Trashing files:
/Users/Shared/Maxon
/Users/Shared/Red Giant
~/Library/Application Support/Maxon
~/Library/Application Support/Red Giant
~/Library/Caches/net.maxon.app-manager
~/Library/Preferences/Maxon
~/Library/Preferences/net.maxon.app-manager.plist
~/Library/Saved Application State/net.maxon.app-manager.savedState
==> Using sudo to gain ownership of path '/Users/Shared/Maxon'
==> Using sudo to gain ownership of path '/Users/Shared/Red Giant'
Warning: The following files could not be trashed, please do so manually:
==> Removing all staged versions of Cask 'maxon'
```

The warning about files not getting trashed should only be shown if
some files didn't get trashed.

Fixes https://github.com/Homebrew/brew/issues/18901
This commit is contained in:
apainintheneck 2024-12-08 15:48:43 -08:00
parent 8fa9b72a96
commit ebede56314

View File

@ -468,9 +468,7 @@ module Cask
trashed = trashed.split(":") trashed = trashed.split(":")
untrashable = untrashable.split(":") untrashable = untrashable.split(":")
return trashed, untrashable if untrashable.empty? trashed_with_permissions, untrashable = untrashable.partition do |path|
untrashable.delete_if do |path|
Utils.gain_permissions(path, ["-R"], SystemCommand) do Utils.gain_permissions(path, ["-R"], SystemCommand) do
system_command! HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift", system_command! HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift",
args: [path], args: [path],
@ -482,6 +480,10 @@ module Cask
false false
end end
trashed += trashed_with_permissions
return trashed, untrashable if untrashable.empty?
opoo "The following files could not be trashed, please do so manually:" opoo "The following files could not be trashed, please do so manually:"
$stderr.puts untrashable $stderr.puts untrashable