Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

History forgets only what has certainly left the Trash, and asks first

Țugui Dragoșcf8fbce7e7c5
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index af8c2272..456d7ae1 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -117,7 +117,8 @@ A handful of ideas carry most of the weight. Each is enforced in one place and t
- **Exclusions everywhere.** The user's exclusions reach every scanner, so an excluded item never appears, and
a folder with something excluded inside is never moved.
- **Unknown stays unknown.** A size that couldn't be measured, a list a tool didn't give, an answer that didn't
- come: each is kept as not known, shown as such, and never selected for the user.
+ come, whether an item is still in the Trash when macOS won't let Peel look (`TrashedItem.standing`): each is
+ kept as not known, shown as such, never selected for the user, and never forgotten from History.
- **Every hold back has a reason.** When Peel takes a checkmark away, the row says why.
## The helper
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index bd99c833..c523e8a7 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -32604,6 +32604,346 @@
}
}
},
+ "Forget ^[%lld item](inflect: true)?" : {
+ "localizations" : {
+ "cs" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zapomenout %lld položky?"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zapomenout %lld položky?"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zapomenout %lld položku?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zapomenout %lld položek?"
+ }
+ }
+ }
+ }
+ },
+ "de" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld Objekt vergessen?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld Objekte vergessen?"
+ }
+ }
+ }
+ }
+ },
+ "es" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "¿Olvidar %lld de ítems?"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "¿Olvidar un ítem?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "¿Olvidar %lld ítems?"
+ }
+ }
+ }
+ }
+ },
+ "fr" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Oublier %lld d’éléments ?"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Oublier %lld élément ?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Oublier %lld éléments ?"
+ }
+ }
+ }
+ }
+ },
+ "it" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Vuoi dimenticare %lld di elementi?"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Vuoi dimenticare un elemento?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Vuoi dimenticare %lld elementi?"
+ }
+ }
+ }
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld項目を履歴から削除しますか?"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "항목 %lld개를 기록에서 지우겠습니까?"
+ }
+ },
+ "nl" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld onderdeel vergeten?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld onderdelen vergeten?"
+ }
+ }
+ }
+ }
+ },
+ "pl" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zapomnieć %lld rzeczy?"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zapomnieć %lld rzeczy?"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zapomnieć %lld rzecz?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zapomnieć %lld rzeczy?"
+ }
+ }
+ }
+ }
+ },
+ "pt" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Esquecer %lld de itens?"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Esquecer %lld item?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Esquecer %lld itens?"
+ }
+ }
+ }
+ }
+ },
+ "ro" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Uitați %lld articole?"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Uitați %lld articol?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Uitați %lld de articole?"
+ }
+ }
+ }
+ }
+ },
+ "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" : "Vill du glömma %lld objekt?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Vill du glömma %lld objekt?"
+ }
+ }
+ }
+ }
+ },
+ "tr" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld öğe unutulsun mu?"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld öğe unutulsun mu?"
+ }
+ }
+ }
+ }
+ },
+ "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個項目的記錄嗎?"
+ }
+ }
+ }
+ },
"Forget the receipt of %@?" : {
"localizations" : {
"cs" : {
@@ -35603,6 +35943,112 @@
}
}
},
+ "History keeps what it can’t see until Peel can look again." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historie si ponechá, co nevidí, dokud se Peel nebude moci znovu podívat."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Der Verlauf behält, was er nicht sehen kann, bis Peel wieder nachsehen kann."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historial conserva lo que no puede ver hasta que Peel pueda volver a mirar."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "L’Historique conserve ce qu’il ne peut pas voir, jusqu’à ce que Peel puisse y regarder à nouveau."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "La Cronologia conserva ciò che non vede finché Peel non potrà guardare di nuovo nel Cestino."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "確認できない項目は、Peelが再び調べられるようになるまで履歴に残ります。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "볼 수 없는 항목은 Peel이 다시 살펴볼 수 있을 때까지 기록에 그대로 보관됩니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geschiedenis bewaart wat Peel niet kan zien, totdat Peel weer kan kijken."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historia zachowuje to, czego nie widzi, dopóki Peel nie będzie mógł znów tam zajrzeć."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Histórico mantém o que não consegue ver até que o Peel possa examinar o Lixo de novo."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Istoricul păstrează ce nu poate vedea până când Peel poate căuta din nou în Coș."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "История сохраняет то, чего не видит, пока Peel снова не сможет туда заглянуть."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historik behåller det som den inte kan se tills Peel kan titta igen."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geçmiş, göremediklerini Peel yeniden bakabilene kadar tutar."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Історія зберігає те, чого не бачить, доки Peel знову не зможе туди зазирнути."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在Peel能够再次查看废纸篓之前,“历史记录”会保留它看不到的项目。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "「歷史記錄」會保留它看不到的項目,直到Peel能再次查看。"
+ }
+ }
+ }
+ },
"Hold Control and Command and drag, instead of aiming for the title bar." : {
"localizations" : {
"cs" : {
@@ -75279,6 +75725,112 @@
}
}
},
+ "Peel can’t look in the Trash right now" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel teď nemůže nahlédnout do koše"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kann derzeit nicht im Papierkorb nachsehen"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede mirar en la papelera ahora mismo"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas regarder dans la corbeille pour l’instant"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Al momento Peel non può guardare nel Cestino"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは現在、ゴミ箱の中を調べられません"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 지금은 휴지통을 살펴볼 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan nu niet in de prullenmand kijken"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może teraz zajrzeć do Kosza"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não consegue examinar o Lixo agora"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu poate căuta momentan în Coș"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel сейчас не может заглянуть в Корзину"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan inte titta i papperskorgen just nu"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel şu anda Çöp Sepeti’nin içine bakamıyor"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel зараз не може зазирнути в Смітник"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel目前无法查看废纸篓"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel目前無法查看「垃圾桶」"
+ }
+ }
+ }
+ },
"Peel can’t see or remove everything yet" : {
"localizations" : {
"cs" : {
@@ -125598,6 +126150,112 @@
}
}
},
+ "What History forgets, it can’t put back afterwards." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Co Historie zapomene, to už pak nemůže vrátit zpět."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Was der Verlauf vergisst, kann er danach nicht mehr zurücklegen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Lo que Historial olvida, no puede restaurarlo después."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ce que l’Historique oublie, il ne peut pas le remettre en place par la suite."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ciò che la Cronologia dimentica, non può più ripristinarlo."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "履歴から削除した項目は、あとから戻すことはできません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "기록에서 지운 항목은 나중에 되돌려 놓을 수 없습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Wat Geschiedenis vergeet, kan Geschiedenis daarna niet meer terugzetten."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tego, co Historia zapomni, nie może potem przywrócić."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O que o Histórico esquece, ele não pode colocar de volta depois."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ce uitați nu mai puteți pune înapoi din Istoric."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "То, что История забудет, она потом не сможет восстановить."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Det som Historik glömmer kan den inte lägga tillbaka efteråt."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geçmiş, unuttuklarını sonradan yerine koyamaz."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Те, що Історія забуде, вона вже не зможе повернути."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "移除记录后,“历史记录”就无法再将相应的项目放回原处。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "「歷史記錄」移除記錄後,就無法再還原這些項目。"
+ }
+ }
+ }
+ },
"What Homebrew Found" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
index 9d7955ed..67f0f1a3 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
@@ -34,6 +34,7 @@ struct Batch {
func state(among records: [RemovalRecord]) -> String {
if records.allSatisfy(\.isStillInTrash) { return "in the Trash" }
if records.contains(where: { !$0.isOnAConnectedDisk }) { return "on a disk that isn't connected" }
+ if records.contains(where: { $0.standing == .notKnown }) { return "can't look in the Trash" }
return restorable.isEmpty ? "gone from the Trash" : "partly gone from the Trash"
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHistory.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHistory.swift
index 2a7be54a..6abffb75 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHistory.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHistory.swift
@@ -55,6 +55,11 @@ public struct RemovalRecord: Sendable, Codable, Hashable, Identifiable {
trashedItem.isInTheTrash
}
+ /// Where the item stands now: in the Trash, gone from it, or not known when macOS won't let Peel look.
+ public var standing: TrashedItem.Standing {
+ trashedItem.standing
+ }
+
/// False while the disk whose Trash holds the item is not connected. The item may still be there, so the
/// record is not treated as missing.
public var isOnAConnectedDisk: Bool {
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index cce10699..8dcd854a 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -34,11 +34,28 @@ public struct TrashedItem: Sendable, Hashable, Codable {
self.identity = identity
}
+ /// Where the item stands now, as the disk says.
+ public enum Standing: Sendable, Equatable {
+ 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
+ }
+
+ public var standing: Standing {
+ var info = stat()
+ guard lstat(trashedURL.path(percentEncoded: false), &info) == 0 else {
+ return errno == ENOENT || errno == ENOTDIR ? .gone : .notKnown
+ }
+ guard let identity else { return .inTheTrash }
+ return Identity(ItemIdentity(info)) == identity ? .inTheTrash : .gone
+ }
+
/// Whether the item is still where it went in the Trash: something is there and, when Peel knows which item
/// went, it is that item.
public var isInTheTrash: Bool {
- guard let identity else { return trashedURL.isThere }
- return Identity(ofItemAt: trashedURL) == identity
+ standing == .inTheTrash
}
}
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/DirectoryHandle.swift b/Packages/PeelCore/Sources/PeelPrivileged/DirectoryHandle.swift
index 3d9d23cf..0cc45bf4 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/DirectoryHandle.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/DirectoryHandle.swift
@@ -77,7 +77,7 @@ public struct ItemIdentity: Codable, Hashable, Sendable {
/// When the item was made, in nanoseconds since 1970.
public let birth: Int64
- init(_ info: stat) {
+ public init(_ info: stat) {
device = Int64(info.st_dev)
inode = UInt64(info.st_ino)
birth = Int64(info.st_birthtimespec.tv_sec) * 1_000_000_000 + Int64(info.st_birthtimespec.tv_nsec)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift
index 684424b8..7540ef2f 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift
@@ -159,6 +159,25 @@ struct HistoryCommandTests {
#expect(parts.first?["tool"] is NSNull)
}
+ /// A removal whose items Peel cannot look at in the Trash is not called gone: nobody knows yet.
+ @Test func aRemovalPeelCannotLookAtIsNotCalledGone() throws {
+ let directory = try TemporaryDirectory()
+ let trashed = try directory.file("home/.Trash/report.pdf")
+ let record = RemovalRecord(
+ batch: UUID(),
+ item: TrashedItem(originalURL: directory.url.appending(path: "home/Documents/report.pdf"), trashedURL: trashed, date: .now),
+ size: 16,
+ source: "Editor",
+ tool: "applications"
+ )
+ try directory.setPermissions(0, of: "home/.Trash")
+ defer { try? directory.setPermissions(0o755, of: "home/.Trash") }
+
+ let batch = try #require(Batch.all(in: [record]).first)
+
+ #expect(batch.state(among: batch.records) == "can't look in the Trash")
+ }
+
/// With nothing recorded, the command prints a sentence rather than an empty table, and `--json` prints an
/// empty list.
@Test func saysSoWhenThereIsNothingToList() async throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
index e3961ba1..55d7874e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
@@ -244,6 +244,29 @@ struct TrashServiceTests {
#expect(FileManager.default.fileExists(atPath: movedLater.trashedURL.path(percentEncoded: false)))
}
+ /// An item is gone from the Trash only when the disk says nothing is there, or another item is. When macOS won't
+ /// let Peel look, whether it is there is not known, and never read as gone, since gone records can be forgotten.
+ @Test func whatPeelCannotSeeInTheTrashIsNotKnownRatherThanGone() throws {
+ let directory = try TemporaryDirectory()
+ let trashed = try directory.file("home/.Trash/report.pdf")
+ let item = TrashedItem(
+ originalURL: directory.url.appending(path: "home/Documents/report.pdf"),
+ trashedURL: trashed,
+ date: .now,
+ identity: TrashedItem.Identity(ofItemAt: trashed)
+ )
+ #expect(item.standing == .inTheTrash)
+
+ try directory.setPermissions(0, of: "home/.Trash")
+ #expect(item.standing == .notKnown)
+ try directory.setPermissions(0o755, of: "home/.Trash")
+
+ try FileManager.default.moveItem(at: trashed, to: directory.url.appending(path: "emptied"))
+ #expect(item.standing == .gone)
+ try directory.file("home/.Trash/report.pdf")
+ #expect(item.standing == .gone, "another item in its place was taken for it")
+ }
+
/// Put Back asks again, of the item it holds open, whether it is the one that moved: another item could take its
/// place between the look and the move.
@Test func putBackLeavesAnotherItemInThePlaceItHolds() throws {
diff --git a/Peel/Views/History/HistoryDetailView.swift b/Peel/Views/History/HistoryDetailView.swift
index 90abe7ce..80bb62d4 100644
--- a/Peel/Views/History/HistoryDetailView.swift
+++ b/Peel/Views/History/HistoryDetailView.swift
@@ -10,26 +10,38 @@ struct HistoryDetailView: View {
/// Nil until the disk has answered. An empty value would show every record as gone from the Trash for a
/// moment, and offer to forget records that are still there.
@State private var standing: Standing?
+ @State private var isAskingToForget = false
let batch: RemovalBatch
- /// Which records are still in the Trash, and which are in the Trash of a disk that isn't connected. Any
- /// other record has left the Trash. It is read off the main actor, so drawing the page never touches the disk.
+ /// Which records are still in the Trash, which are in the Trash of a disk that isn't connected, and which Peel
+ /// can't look at. Any other record has left the Trash. It is read off the main actor, so drawing the page never
+ /// touches the disk.
private struct Standing {
var inTrash: Set<RemovalRecord.ID> = []
var away: Set<RemovalRecord.ID> = []
+ var notKnown: Set<RemovalRecord.ID> = []
@concurrent
static func of(_ records: [RemovalRecord]) async -> Standing {
var standing = Standing()
for record in records {
- if record.isStillInTrash {
+ let place = record.standing
+ if place == .inTheTrash {
standing.inTrash.insert(record.id)
} else if !record.isOnAConnectedDisk {
standing.away.insert(record.id)
+ } else if place == .notKnown {
+ standing.notKnown.insert(record.id)
}
}
return standing
}
+
+ /// The records among `records` that have left the Trash, looked at again.
+ @concurrent
+ static func stillGone(_ records: [RemovalRecord]) async -> [RemovalRecord] {
+ records.filter { $0.standing == .gone && $0.isOnAConnectedDisk }
+ }
}
/// The id of the page's task: the batch, and whether the window is key. When either changes, the page reads
@@ -54,7 +66,15 @@ struct HistoryDetailView: View {
private var missing: [RemovalRecord] {
guard let standing else { return [] }
- return batch.records.filter { !standing.inTrash.contains($0.id) && !standing.away.contains($0.id) }
+ return batch.records.filter {
+ !standing.inTrash.contains($0.id) && !standing.away.contains($0.id) && !standing.notKnown.contains($0.id)
+ }
+ }
+
+ /// Records Peel can't look at in the Trash. Whether they are still there is not known, so the page never offers
+ /// to forget them.
+ private var notKnown: [RemovalRecord] {
+ batch.records.filter { standing?.notKnown.contains($0.id) == true }
}
/// Records in the Trash of a disk that isn't connected. They may still be there, so the page never offers
@@ -109,11 +129,29 @@ struct HistoryDetailView: View {
detail: Text("Peel can only put back what is still there.")
) {
Button("Forget") {
- Task { await history.forget(missing) }
+ isAskingToForget = true
}
.tint(.red)
}
.listRowSeparator(.hidden)
+ .confirmationDialog(Text("Forget ^[\(missing.count) item](inflect: true)?"), isPresented: $isAskingToForget) {
+ Button("Forget", role: .destructive) {
+ // Looked at again first: an item can come back to the Trash, or stop being visible, meanwhile.
+ Task { await history.forget(await Standing.stillGone(missing)) }
+ }
+ Button("Cancel", role: .cancel) {}
+ } message: {
+ Text("What History forgets, it can’t put back afterwards.")
+ }
+ }
+
+ if !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."),
+ kind: .note
+ ) {}
+ .listRowSeparator(.hidden)
}
if !away.isEmpty {
@@ -175,6 +213,7 @@ struct HistoryDetailView: View {
private func place(of record: RemovalRecord, in standing: Standing) -> RecordPlace {
if standing.inTrash.contains(record.id) { return .inTrash }
if standing.away.contains(record.id) { return .onADiskThatIsAway }
+ if standing.notKnown.contains(record.id) { return .notKnown }
return .gone
}
@@ -232,6 +271,7 @@ private struct RestoreBar: View {
private enum RecordPlace {
case inTrash
case onADiskThatIsAway
+ case notKnown
case gone
var symbolName: String { self == .inTrash ? "trash" : "questionmark.circle" }
@@ -241,6 +281,7 @@ private enum RecordPlace {
case .gone: "No longer in the Trash"
case .inTrash: "In the Trash"
case .onADiskThatIsAway: "On a disk that isn’t connected"
+ case .notKnown: "Peel can’t look in the Trash right now"
}
}
}
diff --git a/SAFETY.md b/SAFETY.md
index dec5f797..76243df7 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -133,6 +133,8 @@ root of another disk), asked of the folder itself with every link resolved: a fo
`.Trash`, a link into Messages, or iCloud Drive's own Trash, is refused. And it takes only the very item that
went: History keeps which item it was (its inode and when it was made), so once the Trash is emptied, another
item that lands in the same place, another project's `node_modules`, say, is never put back in its stead.
+History offers to forget a record only once its item has certainly left the Trash, asks first, and looks again
+just before; an item Peel isn't allowed to look at is shown as not known and kept.
## What is selected for you