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 History no longer lists
Țugui Dragoșa6dfe5a9d1bf
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 03c56c4b..64bba564 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -161,8 +161,9 @@ the Homebrew page's uninstall and cleanups are Homebrew's own.7. **Record.**- Every removal goes into History (`removals.json`, through `RemovalLog`), with where each item came from andwhere it went, so it can be put back; History keeps the most recent 20,000 items, fewer when their paths are- very long, since it never writes more than it reads back (`Batches.fitting`). A removal is one entry, even when- it moved what was selected on several pages.+ very long, since it never writes more than it reads back (`Batches.fitting`). It counts the removals it leaves+ out with the totals below, so its page says once how many it no longer lists, and `peel history` says so where+ its list ends. A removal is one entry, even when it moved what was selected on several pages.- As it records, History adds what moved to the totals Home and the menu bar panel show (`totals.json`, through`RemovalTotals`), so the app and `peel` count alike.- Each item is also written down the moment it moves, and what the helper moves as soon as it answers eachdiff --git a/GUIDE.md b/GUIDE.mdindex b516387c..c59511a6 100644--- a/GUIDE.md+++ b/GUIDE.md@@ -330,8 +330,8 @@ 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 Trash- and keeps the latest 20,000 items, fewer when their paths are very long, and, while Peel stays open, Undo in the- Edit menu puts back the last removal you made in it.+ and keeps the latest 20,000 items, fewer when their paths are very long, saying once how many older removals 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, butPeel won't offer to remove or reset it, and leaves out of every page the folders named exactly with its identifier,such as its caches, and an update it downloaded; to keep its other files, such as plug-ins or a folder named afterdiff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 1055e649..423b500b 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -52960,6 +52960,347 @@}}},+ "History no longer lists ^[%lld older removal](inflect: true)" : {+ "comment" : "A note above History’s list, shown once. The number is how many of the oldest removals History left out to stay quick to read, so it no longer lists them.",+ "localizations" : {+ "cs" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historie už neuvádí %lld starší odstranění"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historie už neuvádí %lld staršího odstranění"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historie už neuvádí %lld starší odstranění"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historie už neuvádí %lld starších odstranění"+ }+ }+ }+ }+ },+ "de" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Der Verlauf zeigt %lld älteren Eintrag nicht mehr an"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Der Verlauf zeigt %lld ältere Einträge nicht mehr an"+ }+ }+ }+ }+ },+ "es" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historial ya no muestra %lld de eliminaciones más antiguas"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historial ya no muestra una eliminación más antigua"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historial ya no muestra %lld eliminaciones más antiguas"+ }+ }+ }+ }+ },+ "fr" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "L’Historique ne liste plus %lld d’anciennes suppressions"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "L’Historique ne liste plus %lld ancienne suppression"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "L’Historique ne liste plus %lld anciennes suppressions"+ }+ }+ }+ }+ },+ "it" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La Cronologia non elenca più %lld di rimozioni meno recenti"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La Cronologia non elenca più una rimozione meno recente"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La Cronologia 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" : "Geschiedenis toont %lld oudere verwijdering niet meer"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Geschiedenis toont %lld oudere verwijderingen niet meer"+ }+ }+ }+ }+ },+ "pl" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historia nie wyświetla już %lld starszych przeniesień do Kosza"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historia nie wyświetla już %lld starszych przeniesień do Kosza"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historia nie wyświetla już %lld starszego przeniesienia do Kosza"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historia nie wyświetla już %lld starszego przeniesienia do Kosza"+ }+ }+ }+ }+ },+ "pt" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O Histórico não lista mais %lld de remoções mais antigas"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O Histórico não lista mais %lld remoção mais antiga"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O Histórico não lista mais %lld remoções mais antigas"+ }+ }+ }+ }+ },+ "ro" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Istoricul nu mai listează %lld eliminări mai vechi"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Istoricul nu mai listează %lld eliminare mai veche"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Istoricul nu mai listează %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" : "Historik listar inte längre %lld äldre borttagning"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historik listar inte längre %lld äldre borttagningar"+ }+ }+ }+ }+ },+ "tr" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Geçmiş artık %lld eski kaldırma işlemini listelemiyor"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Geçmiş 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次較早的移除"+ }+ }+ }+ },"History stops listing them. They have already left the Trash, so nothing on your Mac changes." : {"localizations" : {"cs" : {@@ -208636,6 +208977,113 @@}}},+ "What was moved is still in the Trash unless you emptied it." : {+ "comment" : "Under that note: what those older removals moved stays in the Trash until the person empties it.",+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Co se přesunulo, je stále v koši, pokud jste ho nevysypali."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Was verschoben wurde, liegt noch im Papierkorb, sofern du ihn nicht entleert hast."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lo que se trasladó sigue en la papelera, salvo que la hayas vaciado."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ce qui a été déplacé se trouve toujours dans la corbeille, sauf si vous l’avez vidée."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ciò che è stato spostato è ancora nel Cestino, a meno che tu non l’abbia svuotato."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "移動した項目は、ゴミ箱を空にしていなければ、まだゴミ箱にあります。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "휴지통을 비우지 않았다면 이동된 항목은 아직 휴지통에 있습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Wat is verplaatst, staat nog in de prullenmand, tenzij je die hebt geleegd."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "To, co przeniesiono, nadal jest w Koszu, chyba że go opróżniono."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O que foi movido continua no Lixo, a menos que você o tenha esvaziado."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ce s‑a mutat se află în continuare în Coș, dacă nu l‑ați golit."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "То, что было перемещено, по-прежнему находится в Корзине, если Вы ее не очистили."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Det som flyttades ligger fortfarande i papperskorgen, om du inte har tömt den."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Taşınanlar, Çöp Sepeti’ni boşaltmadıysanız hâlâ orada duruyor."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Те, що було переміщено, досі лежить у Смітнику, якщо ви його не очистили."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "除非你已清倒废纸篓,否则移走的内容仍在废纸篓中。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "除非你已清空「垃圾桶」,否則已移動的項目仍在「垃圾桶」中。"+ }+ }+ }+ },"What you move to the Trash with Peel shows up here, and can be put back while it’s still in the Trash." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swiftindex c26fdcca..0d5bb9c3 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift@@ -185,7 +185,8 @@ struct HistoryCommand: AsyncParsableCommand {guard let records = outcome.records else {throw CommandFailure("Peel couldn't read its History.\(outcome.problem.map { " \($0.summary)" } ?? "")")}- let batches = Array(Batch.all(in: records).prefix(shown))+ let all = Batch.all(in: records)+ let batches = Array(all.prefix(shown))if output.json {try Output.json(batches.map { batch in@@ -208,6 +209,11 @@ struct HistoryCommand: AsyncParsableCommand {} else {Output.table(Self.rows(for: batches))}+ // Said where the list reaches History's oldest removal, below which the older ones would be.+ if outcome.noLongerListed > 0, batches.count == all.count {+ let removals = Output.count(outcome.noLongerListed, "older removal", "older removals")+ Output.note("History no longer lists \(removals). What was moved is still in the Trash unless you emptied it.")+ }if let problem = outcome.problem {Output.note(problem.summary)}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swiftindex 2649ede8..dde04dbe 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift@@ -19,6 +19,8 @@ public enum RemovalLogProblem: Sendable, Equatable {public struct RemovalLogOutcome: Sendable {public let records: [RemovalRecord]?public let problem: RemovalLogProblem?+ /// How many older removals the log no longer lists, as the totals count them.+ public let noLongerListed: Int}/// The record of everything Peel moved to the Trash, so History can put it back.@@ -59,7 +61,7 @@ public actor RemovalLog {/// Reads the log. The read takes the lock too, because reading a damaged file sets it aside and writes back/// the rows that could be read.public func load() -> RemovalLogOutcome {- whileNoOtherProcessWrites { RemovalLogOutcome(records: current(), problem: problem) }+ whileNoOtherProcessWrites { outcome(current()) }}/// The places in the Trash where an item Peel moved still is, whichever process moved it: what History records@@ -71,13 +73,12 @@ public actor RemovalLog {public func add(_ records: [RemovalRecord]) -> RemovalLogOutcome {whileNoOtherProcessWrites {- guard !records.isEmpty else { return RemovalLogOutcome(records: current(), problem: problem) }- guard let existing = current() else { return RemovalLogOutcome(records: nil, problem: problem) }+ guard !records.isEmpty else { return outcome(current()) }+ guard let existing = current() else { return outcome(nil) }let new = Set(records.map(\.batch))- let trimmed = Self.trimmed(existing + records, keeping: new)- guard let updated = write(trimmed, keeping: new, orNote: .couldNotRecord) else {+ guard let updated = write(existing + records, keeping: new, orNote: .couldNotRecord) else {journal.keep(records)- return RemovalLogOutcome(records: nil, problem: problem)+ return outcome(nil)}RemovalTotals.change(at: totals) { $0.add(records) }// The journal is what records these items if History is lost, so it lets them go only once History is on@@ -87,7 +88,7 @@ public actor RemovalLog {}// A removal that is recorded clears an earlier `.couldNotRecord`.if problem == .couldNotRecord { problem = nil }- return RemovalLogOutcome(records: updated, problem: problem)+ return outcome(updated)}}@@ -134,12 +135,19 @@ public actor RemovalLog {public func remove(_ ids: Set<UUID>) -> RemovalLogOutcome {whileNoOtherProcessWrites {- guard let existing = current() else { return RemovalLogOutcome(records: nil, problem: problem) }+ guard let existing = current() else { return outcome(nil) }let updated = existing.filter { !ids.contains($0.id) }- return RemovalLogOutcome(records: write(updated, orNote: .couldNotUpdate), problem: problem)+ return outcome(write(updated, orNote: .couldNotUpdate))}}+ /// What a read or change of the log answers, once it has `records` or left the file untouched (nil).+ private func outcome(_ records: [RemovalRecord]?) -> RemovalLogOutcome {+ RemovalLogOutcome(+ records: records, problem: problem, noLongerListed: RemovalTotals.read(beside: url).noLongerListed+ )+ }+/// Runs `change` under a file lock. The app and `peel` both write this log, and the actor keeps order only/// inside one process.private func whileNoOtherProcessWrites<T>(_ change: () -> T) -> T {@@ -176,8 +184,9 @@ public actor RemovalLog {var updated = recordsif !interrupted.isEmpty {let taken = Set(interrupted.map(\.batch))- let trimmed = Self.trimmed(records + interrupted, keeping: taken)- guard let written = write(trimmed, keeping: taken, orNote: .couldNotRecord) else { return records }+ guard let written = write(records + interrupted, keeping: taken, orNote: .couldNotRecord) else {+ return records+ }updated = writtenRemovalTotals.change(at: totals) { $0.add(interrupted) }}@@ -227,8 +236,8 @@ public actor RemovalLog {}}- /// Writes `records`, less the oldest removals that wouldn't fit in what is read back, never one in `protected`,- /// and answers what it wrote, or nil when it couldn't.+ /// Writes `records`, less the oldest removals beyond `maximumRecords` or what is read back, never one in+ /// `protected`, counts those it left out in the totals, and answers what it wrote, or nil when it couldn't.private func write(_ records: [RemovalRecord], keeping protected: Set<UUID> = [], orNote failure: RemovalLogProblem) -> [RemovalRecord]? {@@ -237,8 +246,8 @@ public actor RemovalLog {encoder.outputFormatting = [.prettyPrinted, .sortedKeys]do {let fitted = try Batches.fitting(- records, within: readLimit, batch: \.batch, date: \.date, keeping: protected,- encode: { try encoder.encode($0) }+ Self.trimmed(records, keeping: protected), within: readLimit, batch: \.batch, date: \.date,+ keeping: protected, encode: { try encoder.encode($0) })try FileManager.default.createDirectory(at: url.deletingLastPathComponent(),@@ -248,6 +257,10 @@ public actor RemovalLog {try fitted.data.write(to: url, options: .atomic)// Every writer takes the lock, so the file here is the one just written.kept = FileIdentity.of(url).map { ($0, fitted.records) }+ if fitted.records.count < records.count {+ let leftOut = Set(records.map(\.batch)).subtracting(fitted.records.map(\.batch)).count+ RemovalTotals.change(at: totals) { $0.countNoLongerListed(leftOut) }+ }return fitted.records} catch {// An unrecorded removal is the most serious problem, so a later failure never replaces it.diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalTotals.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalTotals.swiftindex 1b9a6feb..9185425c 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalTotals.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalTotals.swift@@ -10,11 +10,15 @@ public struct RemovalTotals: Sendable, Equatable, Codable {public private(set) var items = 0public private(set) var apps = 0public 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 }/// 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?/// Whether the totals the app kept on its own, before `peel` counted too, were added.private var tookInEarlier = false+ /// The removals History left out, absent from totals written before it counted them.+ private var removalsLeftOut: Int?private struct Removal: Sendable, Equatable, Codable {let batch: UUID@@ -49,6 +53,11 @@ public struct RemovalTotals: Sendable, Equatable, Codable {}}+ /// Counts `count` more removals History left out.+ mutating func countNoLongerListed(_ count: Int) {+ removalsLeftOut = noLongerListed.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 2f31c0c4..6e1aaade 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift@@ -110,6 +110,19 @@ struct HistoryCommandTests {return collected.output}+ /// What `arguments` write to standard error.+ private func noted(+ _ arguments: [String],+ from logs: (removals: RemovalLog, refusals: RefusalLog)+ ) async throws -> String {+ let collected = Output.Collected()+ try await Output.$collected.withValue(collected) {+ try await (command(arguments) as HistoryCommand)+ .run(in: logs.removals, refusals: logs.refusals, trash: movesNothing)+ }+ return collected.notes+ }+private func listed(_ json: String) throws -> [Any] {try #require(try JSONSerialization.jsonObject(with: Data(json.utf8)) as? [Any])}@@ -228,6 +241,37 @@ struct HistoryCommandTests {#expect(try listed(try await printed(["history", "--refused", "--json"], from: logs)).isEmpty)}+ /// A list that reaches History's oldest removal says how many older removals History no longer lists, in the+ /// table and in `--json` alike; one that `--limit` cuts short doesn't.+ @Test func saysWhatHistoryNoLongerListsWhereTheListEnds() async throws {+ let directory = try TemporaryDirectory()+ let removals = RemovalLog(url: directory.url.appending(path: "Peel/removals.json"), flush: { _ in true }, readLimit: 4_096)+ let logs = (removals: removals, refusals: RefusalLog(url: directory.url.appending(path: "Peel/refusals.json")))+ let count = 12+ for index in 0..<count {+ let name = "書類書類書類書類書類書類 \(index)"+ _ = await removals.add([RemovalRecord(+ batch: UUID(),+ item: TrashedItem(+ originalURL: URL(filePath: "/Users/me/\(name)"),+ trashedURL: URL(filePath: "/Users/me/.Trash/\(name)"),+ date: Date(timeIntervalSince1970: Double(index) * 60)+ ),+ size: 1,+ source: "Editor",+ tool: "applications"+ )])+ }+ let listed = Batch.all(in: try #require(await removals.load().records)).count+ try #require(listed > 1 && listed < count)+ let leftOut = Output.count(count - listed, "older removal", "older removals")+ let note = "History no longer lists \(leftOut). What was moved is still in the Trash unless you emptied it.\n"++ #expect(try await noted(["history"], from: logs) == note)+ #expect(try await noted(["history", "--json"], from: logs) == note)+ #expect(try await noted(["history", "--limit", "\(listed - 1)"], from: logs).isEmpty)+ }+/// `--limit` is what the command prints, in the table and in `--json` alike, and 20 without it.@Test func showsAtMostWhatWasAskedFor() async throws {let directory = try TemporaryDirectory()diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swiftindex 57094fbf..773e9d96 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift@@ -392,6 +392,37 @@ struct RemovalHistoryTests {#expect(!batches.contains(removals[0]), "the oldest removal was kept past the limit")}+ /// History counts the removals it leaves out to stay within what it reads back, so it can say what it no+ /// longer lists.+ @Test func countsTheRemovalsItLeavesOut() async throws {+ let directory = try TemporaryDirectory()+ let url = directory.url.appending(path: "Peel/removals.json")+ let log = RemovalLog(url: url, flush: { _ in true }, readLimit: 4_096)+ let removals = [UUID(), UUID(), UUID()]+ var added: RemovalLogOutcome?+ for (index, batch) in removals.enumerated() {+ let date = Date(timeIntervalSince1970: Double(index) * 60)+ added = await log.add((0..<4).map { Self.record(batch: batch, date: date, name: "書類書類書類 \(index) \($0)") })+ }++ let leftOut = removals.count - Set(try #require(added?.records).map(\.batch)).count+ #expect(leftOut > 0)+ #expect(added?.noLongerListed == leftOut)+ #expect(await RemovalLog(url: url, flush: { _ in true }, readLimit: 4_096).load().noLongerListed == leftOut)+ #expect(RemovalTotals.read(beside: url).noLongerListed == leftOut)+ }++ @Test func aRemovalForgottenIsNotCountedAsLeftOut() async throws {+ let directory = try TemporaryDirectory()+ let log = RemovalLog(url: directory.url.appending(path: "Peel/removals.json"))+ let added = await log.add([Self.record(batch: UUID())])++ let forgotten = await log.remove(Set(try #require(added.records).map(\.id)))++ #expect(forgotten.records == [])+ #expect(forgotten.noLongerListed == 0)+ }+@Test func startsNothingOverWhileHistoryCanBeRead() async throws {let directory = try TemporaryDirectory()let url = try directory.file("Peel/removals.json", contents: Data("[]".utf8))diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalTotalsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalTotalsTests.swiftindex 31ff4b78..ee47598d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalTotalsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalTotalsTests.swift@@ -149,6 +149,20 @@ struct RemovalTotalsTests {#expect(kept.contains { $0.hasPrefix("totals-damaged-") })}+ /// Totals written before History counted the removals it leaves out are read as they were.+ @Test func readsTotalsWrittenBeforeHistoryCountedWhatItLeftOut() throws {+ let directory = try TemporaryDirectory()+ let history = directory.url.appending(path: "Peel/removals.json")+ let earlier = #"{"apps":1,"biggest":{"isComplete":true,"known":300},"bytes":{"isComplete":true,"known":500},"items":2,"tookInEarlier":true}"#+ _ = try directory.file("Peel/totals.json", contents: Data(earlier.utf8))++ let totals = RemovalTotals.read(beside: history)++ #expect(totals.items == 2)+ #expect(totals.bytes == SizeTotal(known: 500, isComplete: true))+ #expect(totals.noLongerListed == 0)+ }+@Test func historyIsRecordedWhenTheTotalsCannotBeWritten() async throws {let directory = try TemporaryDirectory()let history = directory.url.appending(path: "Peel/removals.json")diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swiftindex 5455c72e..3c51db40 100644--- a/Peel/Model/RemovalHistoryStore.swift+++ b/Peel/Model/RemovalHistoryStore.swift@@ -160,6 +160,10 @@ final class RemovalHistoryStore {/// What the last read or change of the refusal log met, which the Not Moved list says.private(set) var refusalProblem: RefusalLogProblem?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+ /// 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/// reading it: at launch, when Peel comes forward, and with every read or change of History.private(set) var isUnreadable = false@@ -185,6 +189,7 @@ final class RemovalHistoryStore {/// older change must never replace a newer one.private var listedChange = 0private var refusalChange = 0+ @ObservationIgnored private let defaults: UserDefaultsvar selectedBatch: RemovalBatch? {batches.first { $0.id == selection }@@ -204,9 +209,11 @@ final class RemovalHistoryStore {restoring: @escaping ([TrashedItem], Bool) async -> [RestoreFailure?] = { items, canUseHelper inawait TrashService(exclusions: ExclusionsStore.shared.exclusions).restore(items, canUseHelper: canUseHelper)},- announcing: @escaping (AttributedString) -> Void = { AccessibilityNotification.Announcement($0).post() }+ announcing: @escaping (AttributedString) -> Void = { AccessibilityNotification.Announcement($0).post() },+ defaults: UserDefaults = .standard) {self.log = log+ self.defaults = defaultsself.refusals = refusalsself.outcome = outcomeself.knowsTheExclusions = knowsTheExclusions@@ -251,6 +258,18 @@ final class RemovalHistoryStore {isUnreadable ? .unreadable : problem}+ /// How many older removals History no longer lists, while its page has not said that count yet.+ var untoldNoLongerListed: Int? {+ noLongerListed > 0 && noLongerListed != toldNoLongerListed ? noLongerListed : nil+ }++ /// 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 }+ toldNoLongerListed = count+ defaults.set(count, forKey: SettingsKey.toldNoLongerListed)+ }+/// Looks again at whether History can be read and written, which costs no read of it.func checkReadability() {let unreadable = !RemovalLog.canBeRead(at: log.url)@@ -410,6 +429,12 @@ final class RemovalHistoryStore {private func apply(_ outcome: RemovalLogOutcome) async {problem = outcome.problemcheckReadability()+ if noLongerListed != outcome.noLongerListed {+ if toldNoLongerListed == nil {+ toldNoLongerListed = defaults.integer(forKey: SettingsKey.toldNoLongerListed)+ }+ noLongerListed = outcome.noLongerListed+ }guard let records = outcome.records else { return }// What left History since it was listed, as by `peel restore`, is no longer Undo's to put back.keepUndoable(without: Set(self.records.map(\.id)).subtracting(records.map(\.id)))diff --git a/Peel/Views/History/HistoryList.swift b/Peel/Views/History/HistoryList.swiftindex 9422ba7b..ed6cbb67 100644--- a/Peel/Views/History/HistoryList.swift+++ b/Peel/Views/History/HistoryList.swift@@ -29,6 +29,10 @@ struct HistoryList: View {searchText.isEmpty ? history.refusalBatches : found?.refusals ?? history.refusalBatches}+ private var hasNotices: Bool {+ history.shownProblem != nil || history.refusalProblem != nil || history.untoldNoLongerListed != nil+ }+var body: some View {@Bindable var history = history// Filtered once per body, since the list and the overlay both use the result.@@ -64,11 +68,22 @@ struct HistoryList: View {RefusalProblemNotice(problem: problem).transition(.opacity)}+ // Said once: the page has said it when it goes away.+ if let count = history.untoldNoLongerListed {+ Notice(+ title: Text("History no longer lists ^[\(count) older removal](inflect: true)"),+ detail: Text("What was moved is still in the Trash unless you emptied it."),+ kind: .note+ ) { EmptyView() }+ .transition(.opacity)+ .onDisappear { history.tellNoLongerListed(count) }+ }}.padding(.horizontal, 12)- .padding(.bottom, history.shownProblem != nil || history.refusalProblem != nil ? 8 : 0)+ .padding(.bottom, hasNotices ? 8 : 0).motion(.settle, .movement, value: history.shownProblem != nil).motion(.settle, .movement, value: history.refusalProblem != nil)+ .motion(.settle, .movement, value: history.untoldNoLongerListed != nil)}.overlay {if !history.hasLoaded {diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex adc8a730..c3add46c 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -136,6 +136,8 @@ enum SettingsKey {static let showsInMenuBar = "showsInMenuBar"static let warnsWhenDiskIsNearlyFull = "lowDiskSpace.warns"static let toldDiskIsNearlyFull = "lowDiskSpace.told"+ /// How many older removals History's page last said it no longer lists.+ static let toldNoLongerListed = "history.toldNoLongerListed"/// 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 1a8c6ec3..9c7a9eca 100644--- a/PeelTests/RemovalHistoryStoreTests.swift+++ b/PeelTests/RemovalHistoryStoreTests.swift@@ -43,6 +43,43 @@ struct RemovalHistoryStoreTests {#expect(history.undoTitle == nil, "Undo still offered what peel put back")}+ /// History's page says once how many older removals History no longer lists, and again when it leaves out more.+ @Test func saysOnceWhatHistoryNoLongerLists() async throws {+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: folder) }+ try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)+ let prefs = try MadeUpDefaults()+ defer { prefs.forget() }+ func store() -> RemovalHistoryStore {+ RemovalHistoryStore(+ log: RemovalLog(url: folder.appending(path: "removals.json")),+ refusals: RefusalLog(url: folder.appending(path: "refusals.json")),+ knowsTheExclusions: { true },+ defaults: prefs.defaults+ )+ }+ func leaveOut(_ count: Int) throws {+ let totals = #"{"apps":0,"biggest":{"isComplete":true,"known":0},"bytes":{"isComplete":true,"known":0},"items":0,"removalsLeftOut":\#(count),"tookInEarlier":false}"#+ try Data(totals.utf8).write(to: folder.appending(path: "totals.json"))+ }++ let history = store()+ await history.load()+ #expect(history.untoldNoLongerListed == nil, "said before anything was left out")+ try leaveOut(3)+ await history.load()+ #expect(history.untoldNoLongerListed == 3)+ history.tellNoLongerListed(3)+ #expect(history.untoldNoLongerListed == nil)++ let later = store()+ await later.load()+ #expect(later.untoldNoLongerListed == nil, "said again after it was said")+ try leaveOut(5)+ await later.load()+ #expect(later.untoldNoLongerListed == 5)+ }+@Test func aHistoryThatCannotBeReadIsNotCalledEmpty() async throws {let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")defer { try? FileManager.default.removeItem(at: folder) }diff --git a/SAFETY.md b/SAFETY.mdindex 3a0c8d57..8215747a 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -140,8 +140,8 @@ link moves the link.## Nothing of yours is deleted permanentlyPeel never deletes anything of yours. Everything it removes goes to the Trash, and everything is recorded so-History can put it back; History keeps the most recent 20,000 items, fewer when their paths are very long, and-what it forgets is still in the Trash.+History can put it back; History keeps the most recent 20,000 items, fewer when their paths are very long. What+it forgets is still in the Trash, and History says once how many older removals 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: