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.

Refuse a removal History couldn't keep, before anything moves

Țugui Dragoș3c57640b73ab
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 8027a26a..30db2aec 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -163,7 +163,9 @@ the Homebrew page's uninstall and cleanups are Homebrew's own.
where 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`). 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.
+ its list ends. A removal of more than History can keep and read back (`RemovalLog.mostAtOnce`) is refused
+ before anything moves, by the storage pages' bar and by `Cleanup`. 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 each
diff --git a/GUIDE.md b/GUIDE.md
index c59511a6..0a18b496 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -331,7 +331,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, and
what 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, 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.
+ 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.
- **Exclusions:** files, folders, and apps Peel must never touch. An excluded app still appears in Applications, but
Peel 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 after
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 9e8f6310..08cbaf83 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -52642,6 +52642,347 @@
}
}
},
+ "History can keep at most ^[%lld item](inflect: true) in one removal, so it can put them back. Select fewer, and move the rest afterward." : {
+ "comment" : "Under that title. The number is how many of the selected items History can keep in one removal: 20,000, or fewer when their paths are very long. Moving them in several removals keeps the way back for each.",
+ "localizations" : {
+ "cs" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historie dokáže v rámci jednoho odstranění zaznamenat nejvýše %lld položky, aby je mohla vrátit zpět. Vyberte jich méně a zbývající přesuňte potom."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historie dokáže v rámci jednoho odstranění zaznamenat nejvýše %lld položky, aby je mohla vrátit zpět. Vyberte jich méně a zbývající přesuňte potom."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historie dokáže v rámci jednoho odstranění zaznamenat nejvýše %lld položku, aby ji mohla vrátit zpět. Vyberte jich méně a zbývající přesuňte potom."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historie dokáže v rámci jednoho odstranění zaznamenat nejvýše %lld položek, aby je mohla vrátit zpět. Vyberte jich méně a zbývající přesuňte potom."
+ }
+ }
+ }
+ }
+ },
+ "de" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Der Verlauf kann pro Eintrag höchstens %lld Objekt festhalten, damit es sich zurücklegen lässt. Wähle weniger Objekte aus und verschiebe den Rest danach."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Der Verlauf kann pro Eintrag höchstens %lld Objekte festhalten, damit sie sich zurücklegen lassen. Wähle weniger Objekte aus und verschiebe den Rest danach."
+ }
+ }
+ }
+ }
+ },
+ "es" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historial puede guardar como máximo %lld de ítems en una sola eliminación, para poder restaurarlos. Selecciona menos y traslada el resto después."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historial puede guardar como máximo un ítem en una sola eliminación, para poder restaurarlo. Selecciona menos y traslada el resto después."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historial puede guardar como máximo %lld ítems en una sola eliminación, para poder restaurarlos. Selecciona menos y traslada el resto después."
+ }
+ }
+ }
+ }
+ },
+ "fr" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "L’Historique peut conserver au plus %lld d’éléments par suppression, afin de pouvoir les remettre en place. Sélectionnez-en moins, et déplacez le reste ensuite."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "L’Historique peut conserver au plus %lld élément par suppression, afin de pouvoir le remettre en place. Sélectionnez-en moins, et déplacez le reste ensuite."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "L’Historique peut conserver au plus %lld éléments par suppression, afin de pouvoir les remettre en place. Sélectionnez-en moins, et déplacez le reste ensuite."
+ }
+ }
+ }
+ }
+ },
+ "it" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "La Cronologia può conservare al massimo %lld di elementi in una sola rimozione, così da poterli ripristinare. Selezionane di meno e sposta il resto in seguito."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "La Cronologia può conservare al massimo %lld elemento in una sola rimozione, così da poterlo ripristinare. Selezionane di meno e sposta il resto in seguito."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "La Cronologia può conservare al massimo %lld elementi in una sola rimozione, così da poterli ripristinare. Selezionane di meno e sposta il resto in seguito."
+ }
+ }
+ }
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "履歴で戻せるように記録できるのは、1回の移動につき%lld項目までです。選択する項目を減らし、残りはあとで移動してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "기록은 항목을 되돌려 놓을 수 있도록 보관하는데, 한 번의 제거에 보관할 수 있는 항목은 최대 %lld개입니다. 선택 항목을 줄이고 나머지는 나중에 이동하십시오."
+ }
+ },
+ "nl" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geschiedenis kan in één verwijdering maximaal %lld onderdeel bewaren om het te kunnen terugzetten. Selecteer er minder en verplaats de rest daarna."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geschiedenis kan in één verwijdering maximaal %lld onderdelen bewaren om ze te kunnen terugzetten. Selecteer er minder en verplaats de rest daarna."
+ }
+ }
+ }
+ }
+ },
+ "pl" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historia może zapisać w jednym przeniesieniu do Kosza najwyżej %lld rzeczy, aby móc je przywrócić. Zaznacz mniej rzeczy, a resztę przenieś później."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historia może zapisać w jednym przeniesieniu do Kosza najwyżej %lld rzeczy, aby móc je przywrócić. Zaznacz mniej rzeczy, a resztę przenieś później."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historia może zapisać w jednym przeniesieniu do Kosza najwyżej %lld rzecz, aby móc ją przywrócić. Zaznacz mniej rzeczy, a resztę przenieś później."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historia może zapisać w jednym przeniesieniu do Kosza najwyżej %lld rzeczy, aby móc je przywrócić. Zaznacz mniej rzeczy, a resztę przenieś później."
+ }
+ }
+ }
+ }
+ },
+ "pt" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Histórico pode registrar no máximo %lld de itens em uma única remoção, para poder colocá-los de volta. Selecione menos itens e mova o restante depois."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Histórico pode registrar no máximo %lld item em uma única remoção, para poder colocá-lo de volta. Selecione menos itens e mova o restante depois."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Histórico pode registrar no máximo %lld itens em uma única remoção, para poder colocá-los de volta. Selecione menos itens e mova o restante depois."
+ }
+ }
+ }
+ }
+ },
+ "ro" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Istoricul poate păstra cel mult %lld articole într‑o singură eliminare, pentru a le putea pune înapoi. Selectați mai puține și mutați restul după aceea."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Istoricul poate păstra cel mult %lld articol într‑o singură eliminare, pentru a‑l putea pune înapoi. Selectați mai puține și mutați restul după aceea."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Istoricul poate păstra cel mult %lld de articole într‑o singură eliminare, pentru a le putea pune înapoi. Selectați mai puține și mutați restul după aceea."
+ }
+ }
+ }
+ }
+ },
+ "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 kan hålla reda på högst %lld objekt i en enda borttagning för att kunna lägga tillbaka det. Markera färre och flytta resten efteråt."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Historik kan hålla reda på högst %lld objekt i en enda borttagning för att kunna lägga tillbaka dem. Markera färre och flytta resten efteråt."
+ }
+ }
+ }
+ }
+ },
+ "tr" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geçmiş, yerine koyabilmek için tek bir kaldırma işleminde en fazla %lld öğenin kaydını tutabilir. Daha azını seçin, geri kalanını sonra taşıyın."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geçmiş, yerine koyabilmek için tek bir kaldırma işleminde en fazla %lld öğenin kaydını tutabilir. Daha azını seçin, geri kalanını sonra taşıyın."
+ }
+ }
+ }
+ }
+ },
+ "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 couldn’t be updated" : {
"localizations" : {
"cs" : {
@@ -120535,6 +120876,347 @@
}
}
},
+ "Peel can’t move ^[%lld item](inflect: true) at once" : {
+ "comment" : "An alert’s title when a selection is bigger than History can keep in one removal. The number is how many items are selected, in the thousands.",
+ "localizations" : {
+ "cs" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže přesunout %lld položky najednou"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže přesunout %lld položky najednou"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže přesunout %lld položku najednou"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže přesunout %lld položek najednou"
+ }
+ }
+ }
+ }
+ },
+ "de" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kann %lld Objekt nicht auf einmal verschieben"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kann %lld Objekte nicht auf einmal verschieben"
+ }
+ }
+ }
+ }
+ },
+ "es" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede trasladar %lld de ítems de una vez"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede trasladar %lld ítem de una vez"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede trasladar %lld ítems de una vez"
+ }
+ }
+ }
+ }
+ },
+ "fr" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas déplacer %lld d’éléments à la fois"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas déplacer %lld élément à la fois"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas déplacer %lld éléments à la fois"
+ }
+ }
+ }
+ }
+ },
+ "it" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non può spostare %lld di elementi in una volta sola"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non può spostare %lld elemento in una volta sola"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non può spostare %lld elementi in una volta sola"
+ }
+ }
+ }
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは%lld項目を一度に移動できません"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 항목 %lld개를 한 번에 이동할 수 없음"
+ }
+ },
+ "nl" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan %lld onderdeel niet in één keer verplaatsen"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan %lld onderdelen niet in één keer verplaatsen"
+ }
+ }
+ }
+ }
+ },
+ "pl" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może przenieść naraz %lld rzeczy"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może przenieść naraz %lld rzeczy"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może przenieść naraz %lld rzeczy"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może przenieść naraz %lld rzeczy"
+ }
+ }
+ }
+ }
+ },
+ "pt" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não pode mover %lld de itens de uma vez"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não pode mover %lld item de uma vez"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não pode mover %lld itens de uma vez"
+ }
+ }
+ }
+ }
+ },
+ "ro" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu poate muta %lld articole deodată"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu poate muta %lld articol deodată"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu poate muta %lld de articole deodată"
+ }
+ }
+ }
+ }
+ },
+ "ru" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не может переместить %lld объекта за один раз"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не может переместить %lld объектов за один раз"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не может переместить %lld объект за один раз"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не может переместить %lld объекта за один раз"
+ }
+ }
+ }
+ }
+ },
+ "sv" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan inte flytta %lld objekt på en gång"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan inte flytta %lld objekt på en gång"
+ }
+ }
+ }
+ }
+ },
+ "tr" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel %lld öğeyi tek seferde taşıyamaz"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel %lld öğeyi tek seferde taşıyamaz"
+ }
+ }
+ }
+ }
+ },
+ "uk" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не може перемістити %lld елементи за один раз"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не може перемістити %lld елементів за один раз"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не може перемістити %lld елемент за один раз"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не може перемістити %lld елемента за один раз"
+ }
+ }
+ }
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel无法一次移动%lld个项目"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法一次移動%lld個項目"
+ }
+ }
+ }
+ },
"Peel can’t read its file" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
index 98ee16d1..44d60328 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
@@ -79,8 +79,10 @@ struct Cleanup {
})
Output.line("Total: \(Output.size(total))")
notes.forEach(Output.note)
+ let tooMany = Self.tooMany(moving.map(\.url))
guard !dryRun else {
+ if let tooMany { Output.note(tooMany) }
Output.line(moving.isEmpty ? "Nothing here can be moved." : "Dry run: nothing was moved.")
return
}
@@ -98,6 +100,7 @@ struct Cleanup {
if !refused.isEmpty { throw ExitCode.failure }
return
}
+ if let tooMany { throw CommandFailure(tooMany) }
if !yes {
try Output.confirm(question)
}
@@ -128,6 +131,13 @@ struct Cleanup {
try Self.end(failed: !result.failures.isEmpty, recorded: recorded)
}
+ /// Why History couldn't keep a removal of `urls`, or nil when it can.
+ private static func tooMany(_ urls: [URL]) -> String? {
+ let most = RemovalLog.mostAtOnce(of: urls)
+ guard most < urls.count else { return nil }
+ return "Peel can't move \(Output.count(urls.count, "item", "items")) at once: History can keep at most \(Output.number(most)) in one removal, so it can put them back. Move fewer at a time."
+ }
+
/// Ends a removal that ran: exit 1 when something failed, or when History could not record it, since then only
/// the Trash knows what moved.
static func end(failed: Bool, recorded: Bool) throws {
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift
index dde04dbe..1aa96e2e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift
@@ -30,7 +30,7 @@ public struct RemovalLogOutcome: Sendable {
/// actor reentrancy cannot interleave two of them.
public actor RemovalLog {
/// The most records the file keeps. Past this, the oldest batches are dropped whole, never in part.
- static let maximumRecords = 20_000
+ public static let maximumRecords = 20_000
/// The largest file read as History, since any process of the user can rewrite it. Peel never writes more:
/// records with long paths take several times what short ones do, and the oldest removals go first.
static let maximumBytes = 64 * 1_024 * 1_024
@@ -97,6 +97,28 @@ public actor RemovalLog {
whileNoOtherProcessWrites { RemovalTotals.change(at: totals) { $0.takeIn(earlier) } }
}
+ /// How many of `urls`, moved in one removal, History can keep and still read back: at most `maximumRecords`, and
+ /// fewer when their paths are long. A removal of more is refused before anything moves, since History would lose
+ /// it at the next removal, or could no longer read itself.
+ public static func mostAtOnce(of urls: [URL]) -> Int {
+ let room = maximumBytes / 10 * 9
+ var written = 0
+ var count = 0
+ for url in urls.prefix(maximumRecords) {
+ written += estimatedRecordSize(of: url)
+ guard written <= room else { break }
+ count += 1
+ }
+ return count
+ }
+
+ /// No less than History writes for an item that was at `url`: a kilobyte for the record's own fields, and the
+ /// path three times (where it was, where it went, its place on another disk), as JSON writes a URL, with every
+ /// slash escaped.
+ static func estimatedRecordSize(of url: URL) -> Int {
+ 1_024 + 3 * url.absoluteString.utf8.reduce(0) { $0 + ($1 == UInt8(ascii: "/") ? 2 : 1) }
+ }
+
/// Whether History at `url` can be read, known without reading it: it is not there yet, or it opens as the file
/// it should be. A History that cannot be read is never written over, and nothing moves meanwhile.
public static func canBeRead(at url: URL = RemovalHistory.defaultURL) -> Bool {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift
index e454b999..de7ac283 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift
@@ -41,6 +41,43 @@ struct CleanupTests {
#expect(plan.total.known == 20)
}
+ /// A removal History couldn't keep is refused before anything moves, naming how many items it keeps at once, and
+ /// a dry run says so.
+ @Test func refusesARemovalHistoryCouldNotKeep() async throws {
+ let directory = try TemporaryDirectory()
+ let service = try service(in: directory)
+ let removals = RemovalLog(url: directory.url.appending(path: "Peel/removals.json"))
+ let refusals = RefusalLog(url: directory.url.appending(path: "Peel/refusals.json"))
+ let items = (0...RemovalLog.maximumRecords).map {
+ Cleanup.Item(url: URL(filePath: "/Users/me/Library/Caches/org.example.app\($0)"), size: 1, refusal: nil)
+ }
+ let plan = Cleanup(items: items, source: "Duplicates", tool: "duplicates")
+ let moved = Mutex(false)
+ let said = "Peel can't move 20001 items at once: History can keep at most 20000 in one removal, so it can put them back. Move fewer at a time."
+
+ let collected = Output.Collected()
+ try await Output.$collected.withValue(collected) {
+ try await plan.run(
+ question: "?", dryRun: true, yes: true, using: service, recordingIn: removals, refusals: refusals
+ )
+ }
+ let failure = await #expect(throws: CommandFailure.self) {
+ try await Output.$collected.withValue(Output.Collected()) {
+ try await plan.run(
+ question: "?", dryRun: false, yes: true, using: service, recordingIn: removals, refusals: refusals,
+ move: { _, _ in
+ moved.withLock { $0 = true }
+ return TrashResult()
+ }
+ )
+ }
+ }
+
+ #expect(collected.notes == said + "\n")
+ #expect(failure?.description == said)
+ #expect(!moved.withLock { $0 })
+ }
+
/// While the saved exclusions can't be read nothing moves, and no item is blamed on a protected location or
/// recorded as refused: the cause is the list, which the command names.
@Test func movesNothingAndBlamesNoItemWhileTheExclusionsCannotBeRead() async throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift
index 773e9d96..5a2b0b9b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift
@@ -458,6 +458,32 @@ struct RemovalHistoryTests {
#expect(outcome.records?.count == records.count, "the batch lost its tail")
}
+ /// One removal holds at most what History can keep and read back: `maximumRecords` items, fewer when their paths
+ /// are long. A record is never reckoned smaller than History writes it.
+ @Test func tellsHowManyItemsOneRemovalCanHold() throws {
+ let short = (0...RemovalLog.maximumRecords).map { URL(filePath: "/Users/me/Library/Caches/org.example.app\($0)") }
+ let deep = String(repeating: "書類フォルダ/", count: 50)
+ let long = (0..<RemovalLog.maximumRecords).map { URL(filePath: "/Users/me/\(deep)\($0)") }
+
+ #expect(RemovalLog.mostAtOnce(of: Array(short.prefix(10))) == 10)
+ #expect(RemovalLog.mostAtOnce(of: short) == RemovalLog.maximumRecords)
+ #expect(RemovalLog.mostAtOnce(of: long) < RemovalLog.maximumRecords)
+
+ let encoder = JSONEncoder()
+ encoder.dateEncodingStrategy = LogTime.encoding
+ encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
+ for url in [short[0], long[0]] {
+ let record = RemovalRecord(
+ batch: UUID(),
+ item: TrashedItem(
+ originalURL: url, trashedURL: URL(filePath: "/Users/me/.Trash/\(url.lastPathComponent)"), date: .now
+ ),
+ size: .max, source: "Duplicates", sourceKey: "tool", tool: "duplicates", sharedStorage: true
+ )
+ #expect(RemovalLog.estimatedRecordSize(of: url) >= (try encoder.encode([record]).count))
+ }
+ }
+
@Test func trimsWholeBatchesOnly() throws {
let old = (0..<3).map { index -> [RemovalRecord] in
let batch = UUID()
diff --git a/Peel/Views/RemovalBar.swift b/Peel/Views/RemovalBar.swift
index 6038ac27..f4551963 100644
--- a/Peel/Views/RemovalBar.swift
+++ b/Peel/Views/RemovalBar.swift
@@ -15,6 +15,8 @@ struct RemovalBar: View {
@State private var rest: [CarriedSelection.Part] = []
@State private var isAskingToQuit = false
@State private var isShowingPages = false
+ /// A selection History couldn't keep in one removal, which is refused before Peel asks to move it.
+ @State private var tooMany: TooMany?
/// The page's own words under the question, worked out when Move to Trash was pressed.
@State private var pageMessage: Text?
/// The apps last named in `waitingToQuit`, still named while the spinner stays up after the wait.
@@ -263,6 +265,15 @@ struct RemovalBar: View {
} message: {
questionMessage
}
+ .alert(
+ Text("Peel can’t move ^[\(tooMany?.count ?? 0) item](inflect: true) at once"),
+ isPresented: Binding(get: { tooMany != nil }, set: { if !$0 { tooMany = nil } }),
+ presenting: tooMany
+ ) { _ in
+ Button("OK", role: .cancel) {}
+ } message: { tooMany in
+ Text("History can keep at most ^[\(tooMany.most) item](inflect: true) in one removal, so it can put them back. Select fewer, and move the rest afterward.")
+ }
.alert(quitTitle, isPresented: $isAskingToQuit) {
Button("Deselect Them") {
for part in kept.parts { carrier.deselect(part) }
@@ -292,6 +303,10 @@ struct RemovalBar: View {
/// Asks before moving anything, unless open apps keep some of the parts: then they wait until the apps quit or
/// their parts are deselected, and the alert offers to move the rest meanwhile.
private func ask(about parts: [CarriedSelection.Part]) {
+ if let tooMany = Self.tooMany(in: parts) {
+ self.tooMany = tooMany
+ return
+ }
let keptNow = carrier.kept(among: parts)
if !keptNow.isEmpty {
var named: Set<String> = []
@@ -322,6 +337,18 @@ struct RemovalBar: View {
}
}
+ /// How many items `parts` hold and how many History can keep in one removal, when they hold more.
+ static func tooMany(in parts: [CarriedSelection.Part]) -> TooMany? {
+ let urls = parts.flatMap(\.sizes.keys)
+ let most = RemovalLog.mostAtOnce(of: urls)
+ return most < urls.count ? TooMany(count: urls.count, most: most) : nil
+ }
+
+ struct TooMany: Equatable {
+ let count: Int
+ let most: Int
+ }
+
static func lines(for parts: [CarriedSelection.Part]) -> [String] {
let listed = parts.prefix(RemovalFailureAlert.mostListed)
var lines = listed.map(line)
diff --git a/PeelTests/RemovalBarTests.swift b/PeelTests/RemovalBarTests.swift
index 29c30ffa..2c893b24 100644
--- a/PeelTests/RemovalBarTests.swift
+++ b/PeelTests/RemovalBarTests.swift
@@ -26,6 +26,21 @@ struct RemovalBarTests {
#expect(RemovalBar.lines(for: parts(most)).count == most)
}
+ /// A selection History couldn't keep in one removal is refused before Peel asks to move it.
+ @Test func refusesASelectionHistoryCouldNotKeep() {
+ let many = (0...RemovalLog.maximumRecords).map { URL(filePath: "/Users/me/Library/Caches/org.example.app\($0)") }
+ let selection = CarriedSelection.Part(
+ page: Tool.duplicates.page(), title: "Duplicates", source: "Duplicates", sourceKey: "tool",
+ sizes: Dictionary(uniqueKeysWithValues: many.map { ($0, 1) })
+ )
+
+ let tooMany = RemovalBar.tooMany(in: [selection])
+
+ #expect(tooMany?.count == many.count)
+ #expect(tooMany?.most == RemovalLog.maximumRecords)
+ #expect(RemovalBar.tooMany(in: parts(3)) == nil)
+ }
+
@Test func anActionHistoryDoesntRecordWaitsOnlyForTheExclusions() throws {
let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
let unreadable = folder.appending(path: "removals.json")
diff --git a/SAFETY.md b/SAFETY.md
index 3ddfb9f7..b522b053 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -141,7 +141,8 @@ link moves the link.
Peel 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. What
-it forgets is still in the Trash, and History says once how many older removals it no longer lists.
+it 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.
The space is freed when *you* empty the Trash: Peel never does that for you.
That includes what `pkgutil` and Homebrew would delete: