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
Move nothing while History can't be written
Țugui Dragoș1a5469fc854a
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex b3b086ab..627e18d2 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -167,7 +167,8 @@ the Homebrew page's uninstall and cleanups are Homebrew's own.History the next time History is read, as an interrupted removal. Quitting the app waits for a removal untilHistory has it (`QuitGuard`), as `peel` carries on through Control-C (`Uninterrupted`).- While History cannot be read nothing moves (`RemovalLog.canBeRead`, asked by `TrashService` before a removal)- until Start Over, on the History page, sets the unreadable file aside.+ until Start Over, on the History page, sets the unreadable file aside, and while it cannot be written, its folder+ closed 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, oneremoval to an entry.- What only an administrator can move, from a place the helper doesn't serve, stays where it is, and once thediff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 54150b62..c832d22e 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -109258,6 +109258,112 @@}}},+ "Peel can’t write History" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel nemůže zapisovat do Historie"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel kann nicht in den Verlauf schreiben"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel no puede escribir en Historial"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel ne peut pas écrire dans l’Historique"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel non può scrivere nella Cronologia"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peelは履歴に書き込めません"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel이 기록을 쓸 수 없음"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel kan niet naar Geschiedenis schrijven"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel nie może zapisać Historii"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O Peel não consegue gravar o Histórico"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel nu poate scrie în Istoric"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel не удается записать Историю"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel kan inte skriva till Historik"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel, Geçmiş’e yazamıyor"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel не вдається записати Історію"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel无法写入“历史记录”"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel無法寫入「歷史記錄」"+ }+ }+ }+ },"Peel changes these with `git config --global`. Turning one off puts back what was there before Peel, or leaves it to Git." : {"localizations" : {"cs" : {@@ -111824,6 +111930,112 @@}}},+ "Peel couldn’t write to History, because the disk is full or Peel’s folder can’t be written, and it moves nothing it can’t put back." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel nemohl zapsat do Historie, protože disk je plný nebo do složky Peelu nelze zapisovat, a nepřesouvá nic, co nemůže vrátit zpět."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel konnte nicht in den Verlauf schreiben, weil das Volume voll ist oder in den Peel-Ordner nicht geschrieben werden kann, und verschiebt nichts, was sich nicht zurücklegen lässt."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel no ha podido escribir en Historial, porque el disco está lleno o no se puede escribir en la carpeta de Peel, y no traslada nada que no pueda restaurar."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel n’a pas pu écrire dans l’Historique, car le disque est plein ou le dossier de Peel n’est pas accessible en écriture, et il ne déplace rien qu’il ne pourrait pas remettre en place."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel non è riuscito a scrivere nella Cronologia, perché il disco è pieno o non è possibile scrivere nella cartella di Peel, e non sposta nulla che non possa ripristinare."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peelは履歴に書き込めませんでした。ディスクがいっぱいになっているか、Peelのフォルダに書き込めないためです。戻せないものは何も移動しません。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "디스크가 가득 찼거나 Peel의 폴더에 쓸 수 없기 때문에 Peel이 기록을 쓸 수 없었으며, 되돌려 놓을 수 없는 것은 아무것도 이동하지 않습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel kon niet naar Geschiedenis schrijven, omdat de schijf vol is of er niet naar de map van Peel kan worden geschreven, en Peel verplaatst niets wat het niet kan terugzetten."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel nie mógł zapisać Historii, ponieważ dysk jest pełny albo nie można zapisywać w folderze Peel, i nie przenosi niczego, czego nie może przywrócić."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O Peel não conseguiu gravar no Histórico, porque o disco está cheio ou não é possível gravar na pasta do Peel, e não move nada que não possa colocar de volta."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel nu a putut scrie în Istoric, deoarece discul este plin sau nu se poate scrie în dosarul Peel, și nu mută nimic din ce nu poate pune înapoi."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel не удалось записать Историю, так как диск заполнен или запись в папку Peel невозможна, а он не перемещает ничего, что не сможет восстановить."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel kunde inte skriva till Historik, eftersom skivan är full eller det inte går att skriva till Peels mapp, och flyttar inget som den inte kan lägga tillbaka."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel, disk dolu olduğu veya Peel’in klasörüne yazılamadığı için Geçmiş’e yazamadı ve yerine koyamayacağı hiçbir şeyi taşımaz."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel не змогла записати в Історію, бо диск переповнений або папка Peel недоступна для запису, і Peel не переміщує нічого, чого не може повернути."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel无法写入“历史记录”,因为磁盘已满或Peel的文件夹无法写入,而它不会移动任何无法放回原处的内容。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel無法寫入「歷史記錄」,因為磁碟已滿或Peel的檔案夾無法寫入,而它不會移動任何無法還原的項目。"+ }+ }+ }+ },"Peel didn’t look everywhere" : {"localizations" : {"cs" : {@@ -164701,6 +164913,112 @@}}},+ "The disk is full, or Peel’s folder can’t be written. Peel removes nothing until it can, so that everything it moves can be put back." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Disk je plný nebo do složky Peelu nelze zapisovat. Dokud nebude moci zapisovat, Peel nic neodstraní, aby vše, co přesune, šlo vrátit zpět."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Das Volume ist voll, oder in den Peel-Ordner kann nicht geschrieben werden. Peel entfernt nichts, solange das so ist, damit sich alles, was Peel verschiebt, zurücklegen lässt."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "El disco está lleno o no se puede escribir en la carpeta de Peel. Peel no elimina nada hasta que pueda escribir en Historial, para que todo lo que traslade se pueda restaurar."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Le disque est plein, ou le dossier de Peel n’est pas accessible en écriture. Peel ne supprime rien tant qu’il ne peut pas y écrire, afin que tout ce qu’il déplace puisse être remis en place."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Il disco è pieno, oppure non è possibile scrivere nella cartella di Peel. Peel non rimuove nulla finché non riesce a scrivere nella Cronologia, in modo che tutto ciò che sposta si possa ripristinare."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "ディスクがいっぱいになっているか、Peelのフォルダに書き込めない状態です。書き込めるようになるまで、Peelは何もゴミ箱に入れません。移動するものをすべて戻せるようにするためです。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "디스크가 가득 찼거나 Peel의 폴더에 쓸 수 없습니다. 기록을 쓸 수 있게 되기 전까지 Peel은 이동하는 모든 항목을 되돌려 놓을 수 있도록 아무것도 제거하지 않습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "De schijf is vol of er kan niet naar de map van Peel worden geschreven. Peel verwijdert niets totdat het weer kan schrijven, zodat alles wat Peel verplaatst, kan worden teruggezet."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Dysk jest pełny albo nie można zapisywać w folderze Peel. Peel niczego nie przeniesie do Kosza, dopóki nie będzie mógł zapisać Historii, aby wszystko, co przeniesie, można było przywrócić."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O disco está cheio, ou não é possível gravar na pasta do Peel. O Peel não remove nada até conseguir gravar, para que tudo o que ele mover possa ser colocado de volta."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Discul este plin sau nu se poate scrie în dosarul Peel. Peel nu elimină nimic până când nu poate scrie, pentru ca tot ce mută să poată fi pus înapoi."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Диск заполнен, или запись в папку Peel невозможна. Peel ничего не удаляет, пока запись не станет возможной, чтобы все, что он перемещает, можно было восстановить."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Skivan är full, eller så går det inte att skriva till Peels mapp. Peel tar inte bort något förrän det går, så att allt som Peel flyttar kan läggas tillbaka."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Disk dolu veya Peel’in klasörüne yazılamıyor. Peel, Geçmiş’e yazabilene kadar hiçbir şeyi kaldırmaz, böylece taşıyacağı her şey yerine konabilir."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Диск переповнений, або папка Peel недоступна для запису. Peel нічого не вилучає, доки не зможе записувати в Історію, щоб усе, що Peel переміщує, можна було повернути."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "磁盘已满,或者Peel的文件夹无法写入。在能够写入之前,Peel不会移除任何内容,以确保它移动的所有内容都能放回原处。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "磁碟已滿,或Peel的檔案夾無法寫入。在能夠寫入之前,Peel不會移除任何項目,以確保它移動的所有項目都能還原。"+ }+ }+ }+ },"The extra section at the end goes away." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swiftindex 6a9a8f43..bf373782 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift@@ -439,6 +439,7 @@ extension TrashFailure.Reason {case .movedWithoutATrace: "in the Trash where macOS didn't say, so only Finder can put it back"case .somethingElseMoved(let name): "something else was at that path; it is in the Trash as \(Output.plain(name))"case .historyUnreadable: "History can't be read"+ case .historyCannotBeWritten: "History can't be written: the disk is full, or Peel's folder can't be written"case .heldOpen(let processes) where processes.count > 1:"in use by \(processes.map(Output.plain).joined(separator: ", ")); quit them, or stop them in Background Items if they have no window, then try again"case .heldOpen(let processes):diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalJournal.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalJournal.swiftindex a78e10b2..ab6c7ed2 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalJournal.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalJournal.swift@@ -70,6 +70,10 @@ struct RemovalJournal: Sendable {RemovalLog.canBeRead(at: history)}+ var historyCanBeWritten: Bool {+ RemovalLog.canBeWritten(at: history)+ }+/// Writes down `items`, which moved together in `batch`, one line each. An item the journal was in, Peel's own/// folder as Peel removes itself, is left out: History went with it, and writing the line would make the/// folder again.diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swiftindex cf86492e..35f73c44 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift@@ -95,6 +95,26 @@ public actor RemovalLog {url.isMissing || BoundedRead.opens(url, maximum: maximumBytes)}+ /// Whether a removal could be recorded in History at `url` now: the folder it is written into can be written, and+ /// its disk has room for the copy a safe write makes of the whole file, with a megabyte to spare.+ public static func canBeWritten(+ at url: URL = RemovalHistory.defaultURL,+ freeSpace: (URL) -> UInt64? = RemovalLog.freeSpace(at:)+ ) -> Bool {+ var folder = url.deletingLastPathComponent()+ while folder.isMissing, folder.path(percentEncoded: false) != "/" { folder = folder.deletingLastPathComponent() }+ guard access(folder.path(percentEncoded: false), W_OK) == 0, let free = freeSpace(folder) else { return false }+ let size = (try? url.resourceValues(forKeys: [.fileSizeKey]).fileSize).map { UInt64($0) } ?? 0+ return free >= size + 1_000_000+ }++ /// The space free on the disk holding `folder`, as `statfs(2)` gives it.+ public static func freeSpace(at folder: URL) -> UInt64? {+ var info = statfs()+ guard statfs(folder.path(percentEncoded: false), &info) == 0 else { return nil }+ return UInt64(info.f_bavail) * UInt64(info.f_bsize)+ }+/// Keeps a History that cannot be read beside the new one, under another name, and starts recording again.public func startOver() -> RemovalLogOutcome {whileNoOtherProcessWrites {diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swiftindex 3d526cc1..49bfc3f9 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift@@ -82,6 +82,8 @@ public struct TrashFailure: Sendable, Hashable {case somethingElseMoved(named: String)/// History cannot be read, so nothing moves: what moved could not be listed for Put Back.case historyUnreadable+ /// History cannot be written, as on a full disk, so nothing moves: what moved could not be listed for Put Back.+ case historyCannotBeWritten/// These processes hold a file open in it, and moving it would pull it from under them.case heldOpen(by: [String])/// Peel itself runs from it or from inside it, and only Remove Peel moves Peel.@@ -111,7 +113,7 @@ extension TrashFailure.Reason {/// state: History it cannot read, or the helper it needs.public var isAboutTheItem: Bool {switch self {- case .historyUnreadable, .needsHelper: false+ case .historyUnreadable, .historyCannotBeWritten, .needsHelper: falsecase .guarded, .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .locked, .movedWithoutATrace,.somethingElseMoved, .heldOpen, .peelRunsFromIt, .heldByAnotherAccount, .openForAnotherUser,.heldByABuildTool, .inUseByMacOS, .failed: true@@ -139,6 +141,7 @@ extension TrashFailure.Reason {case .movedWithoutATrace: "moved-without-a-trace"case .somethingElseMoved: "something-else-moved"case .historyUnreadable: "history-unreadable"+ case .historyCannotBeWritten: "history-cannot-be-written"case .heldOpen: "held-open"case .peelRunsFromIt: "peel-runs-from-it"case .heldByAnotherAccount: "held-by-another-account"@@ -177,6 +180,7 @@ extension TrashFailure.Reason {case "moved-without-a-trace": self = .movedWithoutATracecase "something-else-moved": self = .somethingElseMoved(named: detail ?? "")case "history-unreadable": self = .historyUnreadable+ case "history-cannot-be-written": self = .historyCannotBeWrittencase "held-open": self = .heldOpen(by: (detail ?? "").split(separator: "\n").map(String.init))case "peel-runs-from-it": self = .peelRunsFromItcase "held-by-another-account":@@ -352,14 +356,14 @@ public struct TrashService: Sendable {/// Why every move would be refused now, whatever it is asked to move, or nil when a move may go ahead.public var refusalOfEveryMove: TrashFailure.Reason? {guard knowsTheExclusions else { return .guarded(.exclusionsNotKnown) }- return historyCanBeRead ? nil : .historyUnreadable+ return historyRefusal}/// Why `url` would not move, or nil when it would. A plan can show this before anything moves, since the move/// asks the same guard.public func refusal(of url: URL) -> TrashFailure.Reason? {if let refusal = removalGuard.refusal(of: url) { return .guarded(refusal) }- return historyCanBeRead ? nil : .historyUnreadable+ return historyRefusal}/// Why each of `apps` would not move now in an uninstall, by the checks its move makes: the guard, History, and@@ -386,17 +390,19 @@ public struct TrashService: Sendable {return refusals}- /// Whether the History this service's moves are recorded in can be read. Nothing moves while it cannot, since- /// what moved could not be listed for Put Back.- private var historyCanBeRead: Bool {- journal?.historyCanBeRead ?? true+ /// Why nothing moves while the History this service's moves are recorded in can't be read or written, since what+ /// moved could not be listed for Put Back.+ private var historyRefusal: TrashFailure.Reason? {+ guard let journal else { return nil }+ if !journal.historyCanBeRead { return .historyUnreadable }+ return journal.historyCanBeWritten ? nil : .historyCannotBeWritten}- /// Every item of `urls` refused, while History cannot be read. An item the guard refuses keeps that reason,- /// which outlasts this one.+ /// Every item of `urls` refused, while History can't be read or written. An item the guard refuses keeps that+ /// reason, which outlasts this one.private func refusingAllWhileHistoryCannotBeRead(_ urls: [URL]) -> TrashResult? {- guard !historyCanBeRead else { return nil }- let refused = urls.map { TrashFailure(url: $0, reason: refusal(of: $0) ?? .historyUnreadable) }+ guard let held = historyRefusal else { return nil }+ let refused = urls.map { TrashFailure(url: $0, reason: refusal(of: $0) ?? held) }return TrashResult(failures: refused)}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swiftindex 594b1667..2514f9d8 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift@@ -214,7 +214,7 @@ struct RefusalLogTests {private static let everyReason: [TrashFailure.Reason] = [.guarded(nil), .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .needsHelper,- .movedWithoutATrace, .somethingElseMoved(named: "x 2"), .historyUnreadable,+ .movedWithoutATrace, .somethingElseMoved(named: "x 2"), .historyUnreadable, .historyCannotBeWritten,.heldOpen(by: ["Figma Agent", "java"]), .peelRunsFromIt, .heldByAnotherAccount(by: ["CtxHelper"]),.openForAnotherUser(by: ["Spotify"]), .heldByABuildTool(by: ["Gradle"]),.inUseByMacOS(by: ["geod", "appleaccountd"]), .failed("x"),diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalJournalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalJournalTests.swiftindex 6a8c78c1..dea85d13 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalJournalTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalJournalTests.swift@@ -210,6 +210,34 @@ struct RemovalJournalTests {#expect(await service.trashOwnFiles([item]).trashed.count == 1, "Peel's own files waited for History")}+ @Test(.permissionsHold) func nothingMovesWhileHistoryCannotBeWritten() async throws {+ let directory = try TemporaryDirectory()+ let history = try directory.file("home/Library/Application Support/Peel/removals.json", contents: Data("[]".utf8))+ try directory.setPermissions(0o555, of: "home/Library/Application Support/Peel")+ defer { try? directory.setPermissions(0o755, of: "home/Library/Application Support/Peel") }+ let item = try directory.file("home/Library/Caches/com.example.app/cache.db").deletingLastPathComponent()+ let moved = Mutex<[URL]>([])+ let service = service(in: directory, journal: RemovalJournal(beside: history)) { url in+ moved.withLock { $0.append(url) }+ return directory.url.appending(path: "home/.Trash/\(url.lastPathComponent)")+ }++ #expect(service.refusalOfEveryMove == .historyCannotBeWritten)+ let result = await service.trash([item])++ #expect(moved.withLock { $0 }.isEmpty)+ #expect(result.failures.map(\.reason) == [.historyCannotBeWritten])+ }++ @Test func historyNeedsRoomForTheCopyItsWriteMakes() throws {+ let directory = try TemporaryDirectory()+ let history = try directory.file("Peel/removals.json", contents: Data("[]".utf8))++ #expect(RemovalLog.canBeWritten(at: history))+ #expect(RemovalLog.canBeWritten(at: directory.url.appending(path: "Missing/Peel/removals.json")))+ #expect(!RemovalLog.canBeWritten(at: history, freeSpace: { _ in 1_000 }))+ }+/// Peel's folder holds the journal, and Peel moves it last as it removes itself: that move is not written/// down, since History went with the folder and writing the line would make the folder again.@Test func theMoveOfTheFolderThatHoldsTheJournalMakesNothingAgain() async throws {diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swiftindex 0608304d..e23514c2 100644--- a/Peel/Model/RemovalHistoryStore.swift+++ b/Peel/Model/RemovalHistoryStore.swift@@ -141,6 +141,8 @@ final class RemovalHistoryStore {/// 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+ /// Whether History cannot be written, as on a full disk, which holds every removal back too. Known the same way.+ private(set) var cannotBeWritten = falseprivate(set) var isRestoring = falsevar selection: RemovalBatch.ID?/// By record, not by path: Space and Developer move the same cache folders again and again, so one path@@ -182,9 +184,12 @@ final class RemovalHistoryStore {isUnreadable ? .unreadable : problem}- /// Looks again at whether History can be read, which costs no read of it.+ /// Looks again at whether History can be read and written, which costs no read of it.func checkReadability() {- isUnreadable = !RemovalLog.canBeRead(at: log.url)+ let unreadable = !RemovalLog.canBeRead(at: log.url)+ let unwritable = !unreadable && !RemovalLog.canBeWritten(at: log.url)+ if isUnreadable != unreadable { isUnreadable = unreadable }+ if cannotBeWritten != unwritable { cannotBeWritten = unwritable }}/// Keeps a History that cannot be read beside a new one, and records again.@@ -275,10 +280,12 @@ final class RemovalHistoryStore {/// What the Edit menu shows, and nil when there is nothing to undo.var undoTitle: String? { undoable?.title }- /// Why nothing may move to the Trash or back now: the exclusions are not known, or History can't be read.+ /// Why nothing may move to the Trash or back now: the exclusions are not known, or History can't be read or+ /// written.var holdingReason: TrashFailure.Reason? {guard ExclusionsStore.shared.exclusions.isKnown else { return .guarded(.exclusionsNotKnown) }- return isUnreadable ? .historyUnreadable : nil+ if isUnreadable { return .historyUnreadable }+ return cannotBeWritten ? .historyCannotBeWritten : nil}var mayMove: Bool { holdingReason == nil }diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swiftindex e810c5a2..3fe55ade 100644--- a/Peel/Views/Presentation.swift+++ b/Peel/Views/Presentation.swift@@ -179,6 +179,7 @@ extension TrashFailure.Reason {case .movedWithoutATrace: String(localized: "It is in the Trash, but macOS didn’t say where, so it can only be put back from Finder.", bundle: bundle)case .somethingElseMoved(let name): String(localized: "Something else was at that path by the time it moved. It is in the Trash as \(name), and Finder can put it back.", bundle: bundle)case .historyUnreadable: String(localized: "Peel couldn’t read History, and it moves nothing it can’t put back.", bundle: bundle)+ case .historyCannotBeWritten: String(localized: "Peel couldn’t write to History, because the disk is full or Peel’s folder can’t be written, and it moves nothing it can’t put back.", bundle: bundle)case .heldOpen(let processes) where processes.count > 1:String(localized: "It is in use by \(processes.formatted(.list(type: .and))). Quit \(processes.formatted(.list(type: .and))), or stop them in Background Items if they have no window, then try again.", bundle: bundle)case .heldOpen(let processes):diff --git a/Peel/Views/RemovalsHeldBanner.swift b/Peel/Views/RemovalsHeldBanner.swiftindex 05fcedaf..9c47f0c5 100644--- a/Peel/Views/RemovalsHeldBanner.swift+++ b/Peel/Views/RemovalsHeldBanner.swift@@ -2,7 +2,8 @@ import PeelCoreimport SwiftUI/// Over a page that can move something to the Trash or put it back, while the exclusions or History can't be-/// read: nothing moves until they can, so the page's own button is off, and this says why. It shows only then.+/// read, or History can't be written: nothing moves until they can, so the page's own button is off, and this says+/// why. It shows only then.struct RemovalsHeldBanner: View {@Environment(ExclusionsStore.self) private var exclusions@Environment(RemovalHistoryStore.self) private var history@@ -31,6 +32,13 @@ struct RemovalsHeldBanner: View {}.padding(.vertical, 6).listRowSeparator(.hidden)+ } else if history.cannotBeWritten {+ Notice(+ title: Text("Peel can’t write History"),+ detail: Text("The disk is full, or Peel’s folder can’t be written. Peel removes nothing until it can, so that everything it moves can be put back.")+ ) {}+ .padding(.vertical, 6)+ .listRowSeparator(.hidden)}}}diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex 4ded4200..0142e9c1 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -420,6 +420,10 @@ private struct GeneralSettingsView: View {Text("Peel removes nothing until you start History over, so that everything it moves can be put back.").font(.callout).foregroundStyle(.secondary)+ } else if history.cannotBeWritten {+ Text("The disk is full, or Peel’s folder can’t be written. Peel removes nothing until it can, so that everything it moves can be put back.")+ .font(.callout)+ .foregroundStyle(.secondary)}}// Homebrew removes the links its cask made, and no other.diff --git a/SAFETY.md b/SAFETY.mdindex d435e044..98211a8c 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -227,7 +227,8 @@ Peel, since moving its helper's file would stop the uninstaller halfway.If the record itself is damaged, it is set aside under another name rather than overwritten, because it isthe only way back from a removal. If it can't be read at all, Peel moves nothing, since what it moved then couldn'tbe put back, until it can be read or until you start it over in History, which keeps the old file beside the new-one. The `peel` command says so and moves nothing either.+one. The same holds while it can't be written, on a full disk or when Peel's folder can't be written, until it can.+The `peel` command says so and moves nothing either.The record is also a file any process running as you can rewrite, so Put Back reads it as a request, not asa fact. It only takes something that really sits in a Trash of yours (`~/.Trash`, or `.Trashes/<uid>` at the