From ebede5631462767687d54f9c1ad6d93ecc941b4e Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sun, 8 Dec 2024 15:48:43 -0800 Subject: [PATCH] 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 --- Library/Homebrew/cask/artifact/abstract_uninstall.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 0cfdcad7ba..2242b7961a 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -468,9 +468,7 @@ module Cask trashed = trashed.split(":") untrashable = untrashable.split(":") - return trashed, untrashable if untrashable.empty? - - untrashable.delete_if do |path| + trashed_with_permissions, untrashable = untrashable.partition do |path| Utils.gain_permissions(path, ["-R"], SystemCommand) do system_command! HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift", args: [path], @@ -482,6 +480,10 @@ module Cask false end + trashed += trashed_with_permissions + + return trashed, untrashable if untrashable.empty? + opoo "The following files could not be trashed, please do so manually:" $stderr.puts untrashable