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 peel restore can't see or do, and keep History's dates and limits true
Țugui Dragoșdb6135ff3788
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 71b551e9..170c51db 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -183,7 +183,8 @@ the Homebrew page's uninstall and cleanups are Homebrew's own.until Start Over, on the History page, sets the unreadable file aside, and while it cannot be written, its folderclosed or its disk without room for the copy a safe write makes, nothing moves either (`RemovalLog.canBeWritten`).- What Peel refused to move is recorded too (`refusals.json`), and History lists it under Not Moved, one- removal to an entry.+ removal to an entry, the latest 5,000 items at most, leaving the oldest out whole and counting them in+ `totals.json`, so its page and `peel history --refused` say how many.- What only an administrator can move, from a place the helper doesn't serve, stays where it is, and once theapp has moved, an uninstall records it (`left-for-an-administrator.json`, through `LeftForAnAdministrator`),so Orphaned Files lists it under Needs an Administrator, judged again as its scan judges what it finds.diff --git a/GUIDE.md b/GUIDE.mdindex ed0b435e..33ce613b 100644--- a/GUIDE.md+++ b/GUIDE.md@@ -343,8 +343,9 @@ It sets up the command line as well:- **History:** everything Peel moved to the Trash, ready to put back, from the app and from Terminal alike, andwhat it was asked to move and wouldn't, with the reason for each item. It puts back what is still in the Trashand keeps the latest 20,000 items, fewer when their paths are very long, saying once how many older removals it- no longer lists, and Peel moves no more at once than History can keep. While Peel stays open, Undo in the Edit- menu puts back the last removal you made in it.+ no longer lists, and Peel moves no more at once than History can keep. Not Moved keeps the latest 5,000 items and+ says the same of what it no longer lists. While Peel stays open, Undo in the Edit menu puts back the last removal you+ made in it.- **Exclusions:** files, folders, and apps Peel must never touch. An excluded app still appears in Applications, andits jobs in Background Items, but Peel won't offer to remove or reset it or act on its jobs, and leaves out of everypage the folders named exactly with its identifier, such as its caches, and an update it downloaded; to keep itsdiff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 65a6cc0b..fe2181d8 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -103173,6 +103173,346 @@}}},+ "Not Moved no longer lists ^[%lld older removal](inflect: true)" : {+ "localizations" : {+ "cs" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Seznam Nepřesunuto už neuvádí %lld starší odstranění"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Seznam Nepřesunuto už neuvádí %lld staršího odstranění"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Seznam Nepřesunuto už neuvádí %lld starší odstranění"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Seznam Nepřesunuto už neuvádí %lld starších odstranění"+ }+ }+ }+ }+ },+ "de" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "„Nicht verschoben“ zeigt %lld älteren Eintrag nicht mehr an"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "„Nicht verschoben“ zeigt %lld ältere Einträge nicht mehr an"+ }+ }+ }+ }+ },+ "es" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La lista “Sin trasladar” ya no muestra %lld de eliminaciones más antiguas"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La lista “Sin trasladar” ya no muestra una eliminación más antigua"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La lista “Sin trasladar” ya no muestra %lld eliminaciones más antiguas"+ }+ }+ }+ }+ },+ "fr" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La liste « Non déplacés » ne contient plus %lld d’anciennes suppressions"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La liste « Non déplacés » ne contient plus %lld ancienne suppression"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La liste « Non déplacés » ne contient plus %lld anciennes suppressions"+ }+ }+ }+ }+ },+ "it" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "“Non spostati” non elenca più %lld di rimozioni meno recenti"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "“Non spostati” non elenca più una rimozione meno recente"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "“Non spostati” non elenca più %lld rimozioni meno recenti"+ }+ }+ }+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "古い%lld件の記録は“移動されなかった項目”に表示されなくなりました"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "‘이동되지 않음’에 오래된 제거 내역 %lld개가 더 이상 표시되지 않음"+ }+ },+ "nl" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "De lijst 'Niet verplaatst' toont %lld oudere verwijdering niet meer"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "De lijst 'Niet verplaatst' toont %lld oudere verwijderingen niet meer"+ }+ }+ }+ }+ },+ "pl" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lista „Nie przeniesiono” nie wyświetla już %lld starszych przeniesień do Kosza"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lista „Nie przeniesiono” nie wyświetla już %lld starszych przeniesień do Kosza"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lista „Nie przeniesiono” nie wyświetla już %lld starszego przeniesienia do Kosza"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lista „Nie przeniesiono” nie wyświetla już %lld starszego przeniesienia do Kosza"+ }+ }+ }+ }+ },+ "pt" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "A lista “Não Movidos” não inclui mais %lld de remoções mais antigas"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "A lista “Não Movidos” não inclui mais %lld remoção mais antiga"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "A lista “Não Movidos” não inclui mais %lld remoções mais antigas"+ }+ }+ }+ }+ },+ "ro" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lista „Nu au fost mutate” nu mai include %lld eliminări mai vechi"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lista „Nu au fost mutate” nu mai include %lld eliminare mai veche"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lista „Nu au fost mutate” nu mai include %lld de eliminări mai vechi"+ }+ }+ }+ }+ },+ "ru" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Список «Не перемещено» больше не показывает %lld старых удаления"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Список «Не перемещено» больше не показывает %lld старых удалений"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Список «Не перемещено» больше не показывает %lld старое удаление"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Список «Не перемещено» больше не показывает %lld старого удаления"+ }+ }+ }+ }+ },+ "sv" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Listan Inte flyttat visar inte längre %lld äldre borttagning"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Listan Inte flyttat visar inte längre %lld äldre borttagningar"+ }+ }+ }+ }+ },+ "tr" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Taşınmayanlar artık %lld eski kaldırma işlemini listelemiyor"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Taşınmayanlar artık %lld eski kaldırma işlemini listelemiyor"+ }+ }+ }+ }+ },+ "uk" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Розділ «Не переміщено» більше не показує %lld давніші вилучення"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Розділ «Не переміщено» більше не показує %lld давніших вилучень"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Розділ «Не переміщено» більше не показує %lld давніше вилучення"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Розділ «Не переміщено» більше не показує %lld давнішого вилучення"+ }+ }+ }+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "“未移动”已不再列出较早的%lld次移除"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "「未移動」已不再列出%lld次較早的移除"+ }+ }+ }+ },"Not Opened in %lld Months" : {"localizations" : {"cs" : {@@ -212276,6 +212616,112 @@}}},+ "What each refused stayed where it was." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Co bylo při každém z nich odmítnuto, zůstalo na svém místě."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Was dabei jeweils abgelehnt wurde, ist geblieben, wo es war."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lo que se rechazó en cada una se quedó donde estaba."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ce que chacune a refusé est resté à sa place."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ciò che ognuna ha rifiutato è rimasto dov’era."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "それぞれの記録で移動を拒否された項目は、元の場所に残っています。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "각 제거 때 거부된 항목은 원래 위치에 그대로 남았습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Wat bij elke verwijdering is geweigerd, is gebleven waar het was."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "To, czego odmówiono przy każdym z nich, pozostało na miejscu."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O que foi recusado em cada uma ficou onde estava."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ce a refuzat fiecare eliminare a rămas unde era."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Все, что не было перемещено при удалении, осталось на месте."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Det som nekades vid varje borttagning stannade där det var."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Her birinde reddedilenler olduğu yerde kaldı."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Те, що Peel тоді відмовилася перемістити, лишилося на місці."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "每次移除中被拒绝的内容都仍留在原处。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "每次移除時遭拒絕的項目都保留在原處。"+ }+ }+ }+ },"What is selected goes to the Trash, and History can put it back. The folders it sits in stay, since macOS expects to find them." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swiftindex 66782fb7..f231030e 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift@@ -31,6 +31,8 @@ struct Batch {var restorable: [RemovalRecord] { records.filter { $0.isOnAConnectedDisk(disks) && $0.isStillInTrash } }/// 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 } }/// Each record where its disk is mounted now.static func all(in records: [RemovalRecord], disks: MountedDisks = .now()) -> [Batch] {@@ -298,6 +300,10 @@ struct HistoryCommand: AsyncParsableCommand {} else {Output.table(Self.rows(for: removals.flatMap(\.records)))}+ if read.noLongerListed > 0 {+ let older = Output.count(read.noLongerListed, "older removal", "older removals")+ Output.note("This list no longer lists \(older). What each refused stayed where it was.")+ }}}@@ -367,8 +373,11 @@ struct RestoreCommand: AsyncParsableCommand {let elsewhere = waiting.isEmpty? nil: "\(items) on a disk that isn't connected. Connect it and run the command again."+ let notKnown = batch.notKnownguard !inTheTrash.isEmpty else {- let nothing = "Nothing of that removal is in the Trash anymore, so there is nothing to put back."+ 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."throw CommandFailure(elsewhere ?? nothing)}@@ -376,11 +385,16 @@ struct RestoreCommand: AsyncParsableCommand {Output.table(going.map { [Output.size($0.size), Output.path($0.originalURL)] })Output.line("Total: \(Output.size(going.totalSize))")}- let gone = batch.records.count - inTheTrash.count - waiting.count+ let gone = batch.records.count - inTheTrash.count - waiting.count - notKnown.countif gone > 0 {let items = Output.count(gone, "item is", "items are")Output.note("\(items) no longer in the Trash and can't be put back.")}+ if !notKnown.isEmpty {+ let items = notKnown.count == 1 ? "1 item Peel can't look at in the Trash right now stays" :+ "\(Output.number(notKnown.count)) items Peel can't look at in the Trash right now stay"+ Output.note("\(items) listed.")+ }if let elsewhere {Output.note(elsewhere)}@@ -388,11 +402,19 @@ struct RestoreCommand: AsyncParsableCommand {Output.note("\(Output.plain(Output.path(record.originalURL))) stays: \(failure.summary)")}+ guard !going.isEmpty else {+ Output.line("Nothing of that removal can be put back from here.")+ if dryRun { return }+ throw ExitCode.failure+ }guard !dryRun else {Output.line("Dry run: nothing was moved.")return}- guard !going.isEmpty else { throw ExitCode.failure }+ // As for a move: History would go on listing what came back.+ guard RemovalLog.canBeWritten(at: log.url) else {+ throw CommandFailure("Nothing was put back. \(TrashFailure.Reason.historyCannotBeWritten.summary).")+ }if !yes {try Output.confirm("Put \(Output.count(going.count, "item", "items")) back?")}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swiftindex 5749f891..45a3a4c0 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift@@ -82,10 +82,10 @@ public actor RefusalLog {/// The records, with what is still to be said about the file (`note`). Nil records when the file could not be/// read: what was refused is then not known, which is not the same as nothing refused.- public func load() -> (records: [RefusalRecord]?, problem: RefusalLogProblem?) {+ public func load() -> (records: [RefusalRecord]?, problem: RefusalLogProblem?, noLongerListed: Int) {FileLock.whileReading(beside: url) {let records = current()- return (records, problem)+ return (records, problem, RemovalTotals.read(beside: url).refusalsNoLongerListed)}}@@ -103,14 +103,19 @@ public actor RefusalLog {guard !records.isEmpty else { return nil }return FileLock.whileHeld(beside: url) {guard let existing = current() else { return problem }- let kept = Batches.trimmed(- existing + records, maximum: Self.maximumRecords, batch: { $0.batch ?? $0.id }, date: \.date,- keeping: [batch]+ let every = existing + records+ let trimmed = Batches.trimmed(+ every, maximum: Self.maximumRecords, batch: { $0.batch ?? $0.id }, date: \.date, keeping: [batch])- guard write(kept, keeping: [batch]) else {+ guard write(trimmed, keeping: [batch]) else {note(.couldNotRecord)return problem}+ let listed = Set((kept?.records ?? trimmed).map { $0.batch ?? $0.id })+ let leftOut = Set(every.map { $0.batch ?? $0.id }).subtracting(listed).count+ if leftOut > 0 {+ RemovalTotals.change(at: RemovalTotals.url(beside: url)) { $0.countRefusalsNoLongerListed(leftOut) }+ }if problem == .couldNotRecord { problem = nil }return problem}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalTotals.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalTotals.swiftindex d6cc1d75..05dc3a77 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalTotals.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalTotals.swift@@ -12,6 +12,8 @@ public struct RemovalTotals: Sendable, Equatable, Codable {public private(set) var biggest = SizeTotal(known: 0, isComplete: true)/// How many older removals History no longer lists: past its limits it leaves the oldest out, each whole.public var noLongerListed: Int { removalsLeftOut ?? 0 }+ /// How many older removals Not Moved no longer lists, which it also leaves out whole past its limits.+ public var refusalsNoLongerListed: Int { refusalsLeftOut ?? 0 }/// The removal counted last and what it has moved so far: a removal of several parts is recorded a part at a/// time, and it is the whole of it that can be the biggest.private var last: Removal?@@ -19,6 +21,7 @@ public struct RemovalTotals: Sendable, Equatable, Codable {private var tookInEarlier = false/// The removals History left out, absent from totals written before it counted them.private var removalsLeftOut: Int?+ private var refusalsLeftOut: Int?private struct Removal: Sendable, Equatable, Codable {let batch: UUID@@ -57,6 +60,10 @@ public struct RemovalTotals: Sendable, Equatable, Codable {removalsLeftOut = noLongerListed.addingCapped(count)}+ mutating func countRefusalsNoLongerListed(_ count: Int) {+ refusalsLeftOut = refusalsNoLongerListed.addingCapped(count)+ }+/// Adds, once, the totals the app kept before `peel` counted too, which share no removal with these.mutating func takeIn(_ other: RemovalTotals) {guard !tookInEarlier else { return }diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swiftindex addd1485..23b40c35 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift@@ -575,6 +575,99 @@ struct HistoryCommandTests {#expect(failure?.description == asked)}+ private func restoring(+ _ record: RemovalRecord, _ flag: String, from logs: (removals: RemovalLog, refusals: RefusalLog),+ in directory: borrowing TemporaryDirectory+ ) async throws -> (said: String, failure: (any Error)?) {+ let service = service(in: directory)+ let collected = Output.Collected()+ let command: RestoreCommand = try command(["restore", String(record.batch.uuidString.prefix(8)), flag])+ let failure = await Output.$collected.withValue(collected) { () async -> (any Error)? in+ do {+ try await command.run(in: logs.removals, using: service)+ return nil+ } catch {+ return error+ }+ }+ return (collected.output + collected.notes, failure)+ }++ @Test(.permissionsHold) func aRestoreDoesNotCallGoneWhatPeelCannotLookAt() async throws {+ let directory = try TemporaryDirectory()+ let logs = logs(in: directory)+ let taken = try removal(in: directory)+ let locked = try directory.file("home/.Trash/locked/report.pdf")+ let unseen = RemovalRecord(+ batch: taken.record.batch,+ item: TrashedItem(+ originalURL: directory.url.appending(path: "home/Documents/other.pdf"), trashedURL: locked, date: .now+ ),+ size: 16, source: "Editor", tool: "applications"+ )+ _ = await logs.removals.add([taken.record, unseen])+ try directory.setPermissions(0, of: "home/.Trash/locked")+ defer { try? directory.setPermissions(0o755, of: "home/.Trash/locked") }++ let part = try await restoring(taken.record, "--dry-run", from: logs, in: directory)+ #expect(part.said.contains("1 item Peel can't look at in the Trash right now stays listed."))+ #expect(!part.said.contains("no longer in the Trash"))++ try directory.setPermissions(0o755, of: "home/.Trash/locked")+ try FileManager.default.removeItem(at: taken.record.trashedURL)+ try directory.setPermissions(0, of: "home/.Trash/locked")++ let none = try await restoring(taken.record, "--dry-run", from: logs, in: directory)+ #expect((none.failure as? CommandFailure)?.description+ == "Peel can't look in the Trash right now, so it can't say what could go back.")+ }++ @Test func saysSoWhenEverythingLeftIsRefused() async throws {+ let directory = try TemporaryDirectory()+ let logs = logs(in: directory)+ let taken = try removal(in: directory)+ try directory.file("home/Documents/report.pdf", bytes: 1)+ _ = await logs.removals.add([taken.record])++ let dry = try await restoring(taken.record, "--dry-run", from: logs, in: directory)+ let real = try await restoring(taken.record, "-y", from: logs, in: directory)++ let nothing = "Nothing of that removal can be put back from here."+ #expect(dry.said.contains(nothing))+ #expect(!dry.said.contains("Dry run"))+ #expect(dry.failure == nil)+ #expect(real.said.contains(nothing))+ #expect(real.failure != nil)+ }++ @Test(.permissionsHold) func putsNothingBackWhileHistoryCannotBeWritten() async throws {+ let directory = try TemporaryDirectory()+ let logs = logs(in: directory)+ let taken = try removal(in: directory)+ _ = await logs.removals.add([taken.record])+ try directory.setPermissions(0o500, of: "Peel")+ defer { try? directory.setPermissions(0o755, of: "Peel") }++ let answer = try await restoring(taken.record, "-y", from: logs, in: directory)++ #expect((answer.failure as? CommandFailure)?.description.contains("History can't be written") == true)+ #expect(!FileManager.default.fileExists(atPath: taken.original.path(percentEncoded: false)))+ }++ @Test func saysHowManyRemovalsNotMovedNoLongerLists() async throws {+ let directory = try TemporaryDirectory()+ let logs = logs(in: directory)+ await logs.refusals.add(+ [TrashFailure(url: URL(filePath: "/Users/me/kept.bin"), reason: .guarded(.excluded))],+ source: "Editor", tool: "applications"+ )+ RemovalTotals.change(at: RemovalTotals.url(beside: logs.refusals.url)) {+ $0.countRefusalsNoLongerListed(2)+ }++ #expect(try await noted(["history", "--refused"], from: logs).contains("no longer lists 2 older removals"))+ }+@Test func aDryRunPutsNothingBack() async throws {let directory = try TemporaryDirectory()let logs = logs(in: directory)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swiftindex c35a1693..5ffabfe4 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift@@ -150,6 +150,7 @@ struct RefusalLogTests {let records = try #require(await log.load().records)#expect(records.count == 2_001)#expect(Set(records.map(\.source)) == ["Older", "New"])+ #expect(await log.load().noLongerListed == 1)}@Test func readsUnchangedRefusalsWithoutDecodingThemAgain() async throws {diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swiftindex 9c6a95a7..70cecbe4 100644--- a/Peel/Model/RemovalHistoryStore.swift+++ b/Peel/Model/RemovalHistoryStore.swift@@ -163,6 +163,8 @@ final class RemovalHistoryStore {private(set) var problem: RemovalLogProblem?/// How many older removals History no longer lists, having left them out past its limits.private(set) var noLongerListed = 0+ private(set) var refusalsNoLongerListed = 0+ private var toldRefusalsNoLongerListed: Int?/// The count History's page said last, read from the preferences once History has left something out.private var toldNoLongerListed: Int?/// Whether History cannot be read, which holds every removal back, as the Trash service does. Known without@@ -264,6 +266,18 @@ final class RemovalHistoryStore {noLongerListed > 0 && noLongerListed != toldNoLongerListed ? noLongerListed : nil}+ /// How many older removals Not Moved no longer lists, while History's page has not said that count yet.+ var untoldRefusalsNoLongerListed: Int? {+ refusalsNoLongerListed > 0 && refusalsNoLongerListed != toldRefusalsNoLongerListed+ ? refusalsNoLongerListed : nil+ }++ func tellRefusalsNoLongerListed(_ count: Int) {+ guard toldRefusalsNoLongerListed != count else { return }+ toldRefusalsNoLongerListed = count+ defaults.set(count, forKey: SettingsKey.toldRefusalsNoLongerListed)+ }+/// Notes that History's page said it no longer lists `count` older removals, so it says each count once.func tellNoLongerListed(_ count: Int) {guard toldNoLongerListed != count else { return }@@ -301,8 +315,16 @@ final class RemovalHistoryStore {await showRefusals(await refusals.load())}- private func showRefusals(_ read: (records: [RefusalRecord]?, problem: RefusalLogProblem?)) async {+ private func showRefusals(+ _ read: (records: [RefusalRecord]?, problem: RefusalLogProblem?, noLongerListed: Int)+ ) async {refusalProblem = read.problem+ if refusalsNoLongerListed != read.noLongerListed {+ if toldRefusalsNoLongerListed == nil {+ toldRefusalsNoLongerListed = defaults.integer(forKey: SettingsKey.toldRefusalsNoLongerListed)+ }+ refusalsNoLongerListed = read.noLongerListed+ }refusalChange += 1let change = refusalChangelet records = read.records ?? []diff --git a/Peel/Views/History/HistoryDetailView.swift b/Peel/Views/History/HistoryDetailView.swiftindex d4ff12e9..d8b9e0da 100644--- a/Peel/Views/History/HistoryDetailView.swift+++ b/Peel/Views/History/HistoryDetailView.swift@@ -143,7 +143,9 @@ struct HistoryDetailView: View {.textSelection(.enabled).help(Text(verbatim: batch.title))} details: {- Text("Moved to the Trash \(batch.date, format: .relative(presentation: .named)), on \(batch.date, format: .dateTime.day().month(.wide).year().hour().minute()).")+ TimelineView(.everyMinute) { _ in+ Text("Moved to the Trash \(batch.date, format: .relative(presentation: .named)), on \(batch.date, format: .dateTime.day().month(.wide).year().hour().minute()).")+ }.font(.callout).foregroundStyle(.secondary)FlowLayout {diff --git a/Peel/Views/History/HistoryList.swift b/Peel/Views/History/HistoryList.swiftindex 4726a615..01eec4e8 100644--- a/Peel/Views/History/HistoryList.swift+++ b/Peel/Views/History/HistoryList.swift@@ -32,6 +32,7 @@ struct HistoryList: View {private var hasNotices: Bool {history.shownProblem != nil || history.refusalProblem != nil || history.untoldNoLongerListed != nil+ || history.untoldRefusalsNoLongerListed != nil}var body: some View {@@ -79,6 +80,15 @@ struct HistoryList: View {.transition(.opacity).onDisappear { history.tellNoLongerListed(count) }}+ if let count = history.untoldRefusalsNoLongerListed {+ Notice(+ title: Text("Not Moved no longer lists ^[\(count) older removal](inflect: true)"),+ detail: Text("What each refused stayed where it was."),+ kind: .note+ ) { EmptyView() }+ .transition(.opacity)+ .onDisappear { history.tellRefusalsNoLongerListed(count) }+ }}.padding(.horizontal, 12).padding(.bottom, hasNotices ? 8 : 0)@@ -215,7 +225,9 @@ private struct HistoryBatchRow: View {Text("^[\(batch.records.count) item](inflect: true)")Text(verbatim: batch.size.text).monospacedDigit()- Text(batch.date, format: .relative(presentation: .named))+ TimelineView(.everyMinute) { _ in+ Text(batch.date, format: .relative(presentation: .named))+ }.help(Text(batch.date, format: .dateTime.day().month(.wide).year().hour().minute()))}.lineLimit(1)@@ -235,7 +247,9 @@ private struct RefusalBatchRow: View {} details: {HStack(spacing: 6) {Text("^[\(batch.records.count) item](inflect: true) not moved")- Text(batch.date, format: .relative(presentation: .named))+ TimelineView(.everyMinute) { _ in+ Text(batch.date, format: .relative(presentation: .named))+ }.help(Text(batch.date, format: .dateTime.day().month(.wide).year().hour().minute()))}.lineLimit(1)diff --git a/Peel/Views/History/RefusalDetailView.swift b/Peel/Views/History/RefusalDetailView.swiftindex ee2a8935..8e6af7e5 100644--- a/Peel/Views/History/RefusalDetailView.swift+++ b/Peel/Views/History/RefusalDetailView.swift@@ -14,7 +14,9 @@ struct RefusalDetailView: View {.textSelection(.enabled).help(Text(verbatim: batch.title))} details: {- Text("You asked to move these \(batch.date, format: .relative(presentation: .named)), on \(batch.date, format: .dateTime.day().month(.wide).year().hour().minute()).")+ TimelineView(.everyMinute) { _ in+ Text("You asked to move these \(batch.date, format: .relative(presentation: .named)), on \(batch.date, format: .dateTime.day().month(.wide).year().hour().minute()).")+ }.font(.callout).foregroundStyle(.secondary)}diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex f5e1cca2..c6a6ade3 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -139,6 +139,7 @@ enum SettingsKey {static let toldDiskIsNearlyFull = "lowDiskSpace.told"/// How many older removals History's page last said it no longer lists.static let toldNoLongerListed = "history.toldNoLongerListed"+ static let toldRefusalsNoLongerListed = "history.toldRefusalsNoLongerListed"/// The tools the person chose to show or leave out of the sidebar (`SidebarChoices`).static let sidebarTools = "sidebar.tools"/// The tools left out before each tool had a default, carried into `sidebarTools` once.diff --git a/PeelTests/RemovalHistoryStoreTests.swift b/PeelTests/RemovalHistoryStoreTests.swiftindex f3005c2c..fd306bd3 100644--- a/PeelTests/RemovalHistoryStoreTests.swift+++ b/PeelTests/RemovalHistoryStoreTests.swift@@ -236,6 +236,29 @@ struct RemovalHistoryStoreTests {#expect(records.allSatisfy { history.failures[$0.id] == .needsHelper })}+ @Test func saysOnceHowManyRemovalsNotMovedNoLongerLists() async throws {+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: folder) }+ let made = try MadeUpDefaults()+ defer { made.forget() }+ try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)+ let history = RemovalHistoryStore(+ log: RemovalLog(url: folder.appending(path: "removals.json")),+ refusals: RefusalLog(url: folder.appending(path: "refusals.json")),+ knowsTheExclusions: { true }, defaults: made.defaults+ )+ await history.load()+ #expect(history.untoldRefusalsNoLongerListed == nil)++ let totals = #"{"apps":0,"biggest":{"isComplete":true,"known":0},"bytes":{"isComplete":true,"known":0},"items":0,"refusalsLeftOut":1,"tookInEarlier":false}"#+ try Data(totals.utf8).write(to: folder.appending(path: "totals.json"))+ await history.load()+ #expect(history.untoldRefusalsNoLongerListed == 1)++ history.tellRefusalsNoLongerListed(1)+ #expect(history.untoldRefusalsNoLongerListed == nil)+ }+@Test func aMoveTellsTheJournalWhatItIsCalled() async {let history = RemovalHistoryStore(knowsTheExclusions: { true })diff --git a/SAFETY.md b/SAFETY.mdindex ca971d87..f155f4ea 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -144,7 +144,8 @@ link moves the link.Peel never deletes anything of yours. Everything it removes goes to the Trash, and everything is recorded soHistory can put it back; History keeps the most recent 20,000 items, fewer when their paths are very long. Whatit forgets is still in the Trash, and History says once how many older removals it no longer lists. A removal of-more than History can keep is refused before anything moves.+more than History can keep is refused before anything moves. Its record of what Peel refused to move keeps the latest+5,000 items and says the same of what it no longer lists.The space is freed when *you* empty the Trash: Peel never does that for you.That includes what `pkgutil` and Homebrew would delete: