From fa00d2a9fdda2a141d576591326b751a44ee8f6a Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Sat, 15 Jun 2024 02:51:38 +0100 Subject: [PATCH] cask: fix trash.swift under Xcode 16 --- .../cask/artifact/abstract_uninstall.rb | 13 +++++++------ Library/Homebrew/cask/utils/trash.swift | 17 +++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index a898556c77..fcb8cd77bd 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -457,12 +457,13 @@ module Cask def trash_paths(*paths, command: nil, **_) return if paths.empty? - stdout, stderr, = system_command HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift", - args: paths, - print_stderr: false + stdout, = system_command HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift", + args: paths, + print_stderr: Homebrew::EnvConfig.developer? - trashed = stdout.split(":").sort - untrashable = stderr.split(":").sort + trashed, _, untrashable = stdout.partition("\n") + trashed = trashed.split(":") + untrashable = untrashable.split(":") return trashed, untrashable if untrashable.empty? @@ -470,7 +471,7 @@ module Cask Utils.gain_permissions(path, ["-R"], SystemCommand) do system_command! HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift", args: [path], - print_stderr: false + print_stderr: Homebrew::EnvConfig.developer? end true diff --git a/Library/Homebrew/cask/utils/trash.swift b/Library/Homebrew/cask/utils/trash.swift index cfdd3d896a..cd380aeb1f 100755 --- a/Library/Homebrew/cask/utils/trash.swift +++ b/Library/Homebrew/cask/utils/trash.swift @@ -2,14 +2,6 @@ import Foundation -extension FileHandle : TextOutputStream { - public func write(_ string: String) { - if let data = string.data(using: .utf8) { self.write(data) } - } -} - -var stderr = FileHandle.standardError - let manager = FileManager.default var success = true @@ -17,19 +9,24 @@ var success = true // The command line arguments given but without the script's name let CMDLineArgs = Array(CommandLine.arguments.dropFirst()) +var trashed: [String] = [] +var untrashable: [String] = [] for item in CMDLineArgs { do { let url = URL(fileURLWithPath: item) var trashedPath: NSURL! try manager.trashItem(at: url, resultingItemURL: &trashedPath) - print((trashedPath as URL).path, terminator: ":") + trashed.append((trashedPath as URL).path) success = true } catch { - print(item, terminator: ":", to: &stderr) + untrashable.append(item) success = false } } +print(trashed.joined(separator: ":")) +print(untrashable.joined(separator: ":"), terminator: "") + guard success else { exit(1) }