Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Say what macOS answered when Peel can't look in the Trash
Țugui Dragoș3424425ca726
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 40102267..85cc96bb 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -259854,6 +259854,112 @@}}},+ "macOS answered: %@" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Systém macOS odpověděl: %@"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS antwortete: %@"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS ha respondido: %@"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS a répondu : %@"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS ha risposto: %@"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOSからの応答: %@"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS 응답 내용: %@"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS antwoordde: %@"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS odpowiedział: %@"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O macOS respondeu: %@"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS a răspuns: %@"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ответ macOS: %@"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS svarade: %@"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS’in yanıtı: %@"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Відповідь macOS: %@"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS回应:%@"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "macOS回應:%@"+ }+ }+ }+ },"macOS calls it" : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swiftindex 3325e894..48391313 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift@@ -32,7 +32,21 @@ struct Batch {/// The records on a disk that isn't connected: their items may still be in its Trash.var waiting: [RemovalRecord] { records.filter { !$0.isOnAConnectedDisk(disks) } }/// The records on a connected disk that macOS won't let Peel look at, which may still be in the Trash.- var notKnown: [RemovalRecord] { records.filter { $0.isOnAConnectedDisk(disks) && $0.standing == .notKnown } }+ var notKnown: [RemovalRecord] {+ records.filter { record in+ guard record.isOnAConnectedDisk(disks), case .notKnown = record.standing else { return false }+ return true+ }+ }++ /// What macOS answered when Peel looked for those, each answer once.+ var whyNotKnown: String {+ var answers: [String] = []+ for case .notKnown(let error) in notKnown.map(\.standing) where !answers.contains(error.localizedDescription) {+ answers.append(error.localizedDescription)+ }+ return Output.plain(answers.joined(separator: " "))+ }/// Each record where its disk is mounted now.static func all(in records: [RemovalRecord], disks: MountedDisks = .now()) -> [Batch] {@@ -45,7 +59,7 @@ struct Batch {var state: String {if !waiting.isEmpty { return "on a disk that isn't connected" }if records.allSatisfy(\.isStillInTrash) { return "in the Trash" }- if records.contains(where: { $0.standing == .notKnown }) { return "can't look in the Trash" }+ if !notKnown.isEmpty { return "can't look in the Trash" }return restorable.isEmpty ? "gone from the Trash" : "partly gone from the Trash"}}@@ -377,7 +391,7 @@ struct RestoreCommand: AsyncParsableCommand {guard !inTheTrash.isEmpty else {let nothing = notKnown.isEmpty? "Nothing of that removal is in the Trash anymore, so there is nothing to put back."- : "Peel can't look in the Trash right now, so it can't say what could go back."+ : "Peel can't look in the Trash right now, so it can't say what could go back. macOS answered: \(batch.whyNotKnown)"throw CommandFailure(elsewhere ?? nothing)}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalStanding.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalStanding.swiftindex 2e19c490..8a2a3730 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalStanding.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalStanding.swift@@ -7,6 +7,8 @@ public struct RemovalStanding: Sendable {public private(set) var inTrash: Set<RemovalRecord.ID> = []public private(set) var away: Set<RemovalRecord.ID> = []public private(set) var notKnown: Set<RemovalRecord.ID> = []+ /// What macOS answered when Peel looked for those, each answer once.+ public private(set) var whyNotKnown: [SystemError] = []/// What can be put back, in the removal's order.public private(set) var restorable: [RemovalRecord.ID] = []public private(set) var restorableSize = SizeTotal([])@@ -41,8 +43,9 @@ public struct RemovalStanding: Sendable {if place == .inTheTrash {inTrash.insert(record.id)restorableRecords.append(record)- } else if place == .notKnown {+ } else if case .notKnown(let error) = place {notKnown.insert(record.id)+ if !whyNotKnown.contains(error) { whyNotKnown.append(error) }} else {missingCount += 1}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swiftindex 22a1beb2..03eda764 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift@@ -56,14 +56,16 @@ public struct TrashedItem: Sendable, Hashable, Codable {case inTheTrash/// Nothing is where it went, or, when Peel knows which item went, another item is.case gone- /// macOS would not let Peel look, so whether it is there is not known.- case notKnown+ /// macOS would not let Peel look, so whether it is there is not known, and answered this.+ case notKnown(SystemError)}public var standing: Standing {var info = stat()guard lstat(trashedURL.path(percentEncoded: false), &info) == 0 else {- return errno == ENOENT || errno == ENOTDIR ? .gone : .notKnown+ let code = errno+ guard code != ENOENT, code != ENOTDIR else { return .gone }+ return .notKnown(SystemError(domain: NSPOSIXErrorDomain, code: Int(code)))}guard let identity else { return .inTheTrash }return Identity(ItemIdentity(info)) == identity ? .inTheTrash : .gonediff --git a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swiftindex 466e8a33..ed863397 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift@@ -618,8 +618,9 @@ struct HistoryCommandTests {try directory.setPermissions(0, of: "home/.Trash/locked")let none = try await restoring(taken.record, "--dry-run", from: logs, in: directory)+ let answered = SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES)).localizedDescription#expect((none.failure as? CommandFailure)?.description- == "Peel can't look in the Trash right now, so it can't say what could go back.")+ == "Peel can't look in the Trash right now, so it can't say what could go back. macOS answered: \(answered)")}@Test func aRestoreFailsWhenAnItemWaitsOnADiskThatIsNotConnected() async throws {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalStandingTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalStandingTests.swiftindex 30fc2acb..20bc03a0 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalStandingTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalStandingTests.swift@@ -33,6 +33,7 @@ struct RemovalStandingTests {#expect(standing.inTrash == [kept.id, alsoKept.id])#expect(standing.away == [away.id])#expect(standing.notKnown == [notKnown.id])+ #expect(standing.whyNotKnown == [SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES))])#expect(standing.restorable == [kept.id, alsoKept.id])#expect(standing.restorableSize == SizeTotal([10, nil]))#expect(standing.missingCount == 1)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swiftindex 40dc9a64..27986329 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift@@ -858,7 +858,7 @@ struct TrashServiceTests {#expect(item.standing == .inTheTrash)try directory.setPermissions(0, of: "home/.Trash")- #expect(item.standing == .notKnown)+ #expect(item.standing == .notKnown(SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES))))try directory.setPermissions(0o755, of: "home/.Trash")try FileManager.default.moveItem(at: trashed, to: directory.url.appending(path: "emptied"))diff --git a/Peel/Views/History/HistoryDetailView.swift b/Peel/Views/History/HistoryDetailView.swiftindex fe4eac87..2da804a7 100644--- a/Peel/Views/History/HistoryDetailView.swift+++ b/Peel/Views/History/HistoryDetailView.swift@@ -93,7 +93,10 @@ struct HistoryDetailView: View {if !standing.notKnown.isEmpty {Notice(title: Text("Peel can’t look in the Trash right now"),- detail: Text("History keeps what it can’t see until Peel can look again."),+ detail: Text(verbatim: [+ String(localized: "History keeps what it can’t see until Peel can look again."),+ String(localized: "macOS answered: \(standing.whyNotKnown.map(\.localizedDescription).joined(separator: " "))"),+ ].joined(separator: " ")),kind: .note) {}.listRowSeparator(.hidden)