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.

Say why Put Back leaves an item in the Trash

Țugui Dragoș5e07ed6711d2
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 04789ae1..c0fd729b 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -65159,6 +65159,112 @@
}
}
},
+ "It isn’t in the Trash where Peel put it, so Peel leaves it where it is." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Není to v koši tam, kam to Peel přesunul, takže to Peel nechává, kde to je."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Es liegt nicht an der Stelle im Papierkorb, an die Peel es gelegt hat, daher lässt Peel es, wo es ist."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "No está en la papelera en la que lo puso Peel, así que Peel lo deja donde está."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il n’est plus à l’endroit de la corbeille où Peel l’a placé : Peel le laisse donc là où il est."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non si trova nel Cestino dove Peel l’aveva messo, quindi Peel lo lascia dov’è."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelがゴミ箱に入れた場所にないため、Peelはそのままにします。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 넣어 둔 휴지통 안의 위치에 없으므로, Peel은 이 항목을 지금 있는 곳에 그대로 둡니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het staat niet op de plek in de prullenmand waar Peel het heeft neergezet, dus Peel laat het staan waar het is."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ta rzecz nie znajduje się w Koszu tam, gdzie umieścił ją Peel, więc Peel zostawia ją tam, gdzie jest."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ele não está no Lixo, onde o Peel o colocou, então o Peel o deixa onde está."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nu se află în locul din Coș în care l‑a pus Peel, așa că Peel îl lasă unde este."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Объекта нет в Корзине там, куда его поместил Peel, поэтому Peel оставляет его там, где он находится."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Det ligger inte i papperskorgen där Peel lade det, så Peel låter det vara där det är."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel’in onu Çöp Sepeti’nde koyduğu yerde değil, bu yüzden Peel onu olduğu yerde bırakır."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Його вже немає в тому місці Смітника, куди його поклала Peel, тож Peel лишає його там, де він є."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它已不在Peel将其放入废纸篓时的位置,因此Peel不会移动它。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它已不在Peel當初放入「垃圾桶」的位置,因此Peel會讓它留在原處。"
+ }
+ }
+ }
+ },
"It isn’t in the Trash." : {
"localizations" : {
"cs" : {
@@ -121641,112 +121747,6 @@
}
}
},
- "Peel never puts anything back there." : {
- "localizations" : {
- "cs" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel tam nikdy nic nevrací."
- }
- },
- "de" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel legt dorthin nie etwas zurück."
- }
- },
- "es" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel nunca restaura nada ahí."
- }
- },
- "fr" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel ne remet jamais rien à cet emplacement."
- }
- },
- "it" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel non ripristina mai nulla in quella posizione."
- }
- },
- "ja" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peelがそこに何かを戻すことは決してありません。"
- }
- },
- "ko" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel은 그곳에 절대 아무것도 되돌려 놓지 않습니다."
- }
- },
- "nl" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel zet daar nooit iets terug."
- }
- },
- "pl" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel nigdy niczego tam nie przywraca."
- }
- },
- "pt" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "O Peel nunca coloca nada de volta lá."
- }
- },
- "ro" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel nu pune niciodată nimic înapoi acolo."
- }
- },
- "ru" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel никогда ничего туда не восстанавливает."
- }
- },
- "sv" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel lägger aldrig tillbaka något där."
- }
- },
- "tr" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel oraya asla hiçbir şey geri koymaz."
- }
- },
- "uk" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel ніколи нічого туди не повертає."
- }
- },
- "zh-Hans" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel绝不会将任何内容放回那里。"
- }
- },
- "zh-Hant" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Peel絕不會將任何項目還原到那裡。"
- }
- }
- }
- },
"Peel never resets them for this app." : {
"localizations" : {
"cs" : {
@@ -122596,6 +122596,112 @@
}
}
},
+ "Peel protects that place now, so it puts nothing back there. You can drag it out of the Trash in Finder." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel teď toto místo chrání, takže tam nic nevrací. Ve Finderu to můžete přetáhnout z koše ven."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel schützt diesen Ort jetzt, daher legt Peel dorthin nichts zurück. Du kannst es im Finder aus dem Papierkorb ziehen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel protege ahora ese lugar, así que no restaura nada ahí. Puedes sacarlo de la papelera arrastrándolo en el Finder."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel protège désormais cet emplacement : il n’y remet donc rien. Vous pouvez sortir l’élément de la corbeille dans le Finder, en le faisant glisser."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ora Peel protegge quella posizione, quindi non vi ripristina nulla. Puoi trascinarlo fuori dal Cestino nel Finder."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは現在その場所を保護しているため、そこには何も戻しません。Finderでゴミ箱からドラッグして取り出せます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "이제 Peel이 그 위치를 보호하므로 그곳에 아무것도 되돌려 놓지 않습니다. Finder에서 휴지통 밖으로 드래그하여 꺼낼 수 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel beschermt die plek nu, dus Peel zet daar niets terug. Je kunt het in Finder uit de prullenmand slepen."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel chroni teraz to miejsce, więc niczego tam nie przywraca. Możesz przeciągnąć tę rzecz z Kosza w Finderze."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel agora protege esse local, então não coloca nada de volta lá. Você pode arrastá-lo para fora do Lixo no Finder."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel protejează acum acel loc, așa că nu pune nimic înapoi acolo. În Finder, îl puteți trage afară din Coș."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Теперь Peel защищает это место, поэтому ничего туда не восстанавливает. В Finder объект можно перетащить из Корзины."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel skyddar den platsen nu, så Peel lägger inte tillbaka något där. Du kan dra ut det ur papperskorgen i Finder."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel artık o yeri koruyor, bu yüzden oraya hiçbir şey geri koymaz. Onu Finder’da sürükleyerek Çöp Sepeti’nden çıkarabilirsiniz."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Тепер Peel захищає це місце, тож нічого туди не повертає. У Finder його можна перетягнути зі Смітника."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel现在会保护那个位置,因此不会将任何内容放回那里。你可以在“访达”中将它从废纸篓中拖出来。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel現在會保護該位置,因此不會將任何項目還原到那裡。你可以在Finder中將它從「垃圾桶」拖出來。"
+ }
+ }
+ }
+ },
"Peel removes its helper and login item, moves itself, the files that are certainly its own, and its folder in Application Support to the Trash, all but the Terminal settings zsh and ssh read, clears its settings, then quits. That folder holds History, your exclusions, and Saved Settings. What you set in Tweaks and on the Terminal page stays as it is. The Finder extension goes with the app." : {
"localizations" : {
"cs" : {
@@ -198480,6 +198586,112 @@
}
}
},
+ "Your exclusions in Settings keep Peel from putting anything back there. Take it off the list to put this back, or drag it out of the Trash in Finder." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Vaše výjimky v Nastavení brání Peelu, aby tam cokoli vracel. Chcete-li tuto položku vrátit zpět, odeberte toto místo ze seznamu, nebo ji ve Finderu přetáhněte z koše ven."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Deine Ausschlüsse in den Einstellungen verhindern, dass Peel dorthin etwas zurücklegt. Entferne den Ort aus der Liste, um dies zurückzulegen, oder ziehe es im Finder aus dem Papierkorb."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tus exclusiones en Ajustes impiden que Peel restaure nada ahí. Quita ese lugar de la lista para restaurar esto, o sácalo de la papelera arrastrándolo en el Finder."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Vos exclusions dans les Réglages empêchent Peel de remettre quoi que ce soit à cet emplacement. Retirez cet emplacement de la liste pour remettre cet élément en place, ou sortez-le de la corbeille dans le Finder, en le faisant glisser."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Le tue esclusioni nelle Impostazioni impediscono a Peel di ripristinare qualsiasi cosa in quella posizione. Toglila dall’elenco per ripristinare questo elemento, oppure trascinalo fuori dal Cestino nel Finder."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "“設定”の除外リストにより、Peelはそこに何も戻せません。これを戻すには、その場所をリストから削除するか、Finderでゴミ箱からドラッグして取り出してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "설정의 제외 항목 때문에 Peel은 그곳에 아무것도 되돌려 놓지 않습니다. 이 항목을 되돌려 놓으려면 목록에서 해당 위치를 제거하거나, Finder에서 휴지통 밖으로 드래그하여 꺼내십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Je uitsluitingen in Instellingen voorkomen dat Peel daar iets terugzet. Haal die plek van de lijst om dit terug te zetten, of sleep het in Finder uit de prullenmand."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Twoje wykluczenia w Ustawieniach nie pozwalają aplikacji Peel niczego tam przywracać. Usuń to miejsce z listy, aby przywrócić tę rzecz, albo przeciągnij ją z Kosza w Finderze."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "As suas exclusões nos Ajustes impedem o Peel de colocar qualquer coisa de volta lá. Tire esse local da lista para colocar isto de volta, ou arraste o item para fora do Lixo no Finder."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Excluderile dvs. din Configurări nu îi permit aplicației Peel să pună nimic înapoi acolo. Scoateți acel loc din listă pentru a pune înapoi acest articol sau, în Finder, trageți‑l afară din Coș."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ваши исключения в Настройках не позволяют Peel ничего туда восстанавливать. Чтобы восстановить этот объект, уберите это место из списка исключений или перетащите объект из Корзины в Finder."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dina undantag i Inställningar hindrar Peel från att lägga tillbaka något där. Ta bort platsen från listan om du vill lägga tillbaka det här, eller dra ut det ur papperskorgen i Finder."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ayarlar’daki hariç tutulanlar listeniz, Peel’in oraya bir şey geri koymasını engelliyor. Bunu yerine koymak için o yeri listeden çıkarın veya Finder’da sürükleyerek Çöp Sepeti’nden çıkarın."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Через ваші винятки в Параметрах Peel нічого туди не повертає. Приберіть це місце зі списку, щоб повернути цей елемент, або перетягніть його у Finder зі Смітника."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "你在“设置”中的排除项使Peel无法将任何内容放回那里。将那个位置从列表中移除即可放回此项,或者在“访达”中将它从废纸篓中拖出来。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "你在「設定」中的排除項目讓Peel無法將任何項目還原到那裡。若要還原此項目,請將該位置從列表中移除,或在Finder中將它從「垃圾桶」拖出來。"
+ }
+ }
+ }
+ },
"Your latest changes work in Peel until it quits. When it opens again, and in the peel command, the list is as it was last saved." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 685ce647..3c68ecf7 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -235,7 +235,10 @@ extension RestoreFailure {
case .missingFromTrash: "it isn't in the Trash anymore"
case .alreadyThere: "something is there already"
case .needsHelper: "it needs administrator access, so put it back with the Peel app"
- case .notAllowed: "Peel won't write there"
+ case .notAllowed(.excluded):
+ "your exclusions keep Peel from putting anything there; take it off the list, or drag it out of the Trash in Finder"
+ case .notAllowed(let refusal): "Peel protects that place now (\(refusal.summary)); drag it out of the Trash in Finder"
+ case .notInATrash: "it isn't in the Trash where Peel put it"
case .failed(let message): Output.plain(message)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
index b30e7246..d6a9a87e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
@@ -119,12 +119,8 @@ struct RemovalGuard: Sendable {
refusal(of: url, typeOf: nil)
}
- /// Whether `trashed` may go back to `destination`, which is judged as a removal from there would be, for the
- /// kind of item `trashed` is: nothing is there yet to tell.
- func allowsPuttingBack(_ trashed: URL, at destination: URL) -> Bool {
- refusal(ofPuttingBack: trashed, at: destination) == nil
- }
-
+ /// Why `trashed` may not go back to `destination`, judged as a removal from there would be, for the kind of item
+ /// `trashed` is: nothing is there yet to tell.
func refusal(ofPuttingBack trashed: URL, at destination: URL) -> GuardRefusal? {
refusal(of: destination, typeOf: trashed)
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index 75ee17fc..0911496d 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -200,8 +200,19 @@ public enum RestoreFailure: Sendable, Hashable {
case missingFromTrash
case alreadyThere
case needsHelper
- case notAllowed
+ /// The guard refuses the place it would go back to, for this reason.
+ case notAllowed(GuardRefusal)
+ /// The record names something that isn't in a Trash where Peel put it.
+ case notInATrash
case failed(String)
+
+ /// True when asking again can't help: the item left the Trash, or Peel puts nothing back from or to there.
+ public var isFinal: Bool {
+ switch self {
+ case .missingFromTrash, .notAllowed, .notInATrash: true
+ case .alreadyThere, .needsHelper, .failed: false
+ }
+ }
}
public struct TrashResult: Sendable {
@@ -740,9 +751,10 @@ public struct TrashService: Sendable {
/// Why `item` cannot go back as things stand, or nil when it can.
public func refusal(ofPuttingBack item: TrashedItem) -> RestoreFailure? {
// The record comes from a file any process of the user can rewrite, so it is a request, not a fact.
- // Putting an item back must not write where removal is refused, or move a file that is not in a Trash.
- guard removalGuard.allowsPuttingBack(item.trashedURL, at: item.originalURL), isInATrash(item.trashedURL) else {
- return .notAllowed
+ // Putting an item back must not move a file that is not in a Trash, or write where removal is refused.
+ guard isInATrash(item.trashedURL) else { return .notInATrash }
+ if let refusal = removalGuard.refusal(ofPuttingBack: item.trashedURL, at: item.originalURL) {
+ return .notAllowed(refusal)
}
guard item.isInTheTrash else { return .missingFromTrash }
guard !item.originalURL.isThere else { return .alreadyThere }
@@ -770,8 +782,8 @@ public struct TrashService: Sendable {
do {
try Self.putBack(item) { removalGuard.refusal(ofPuttingBack: item.trashedURL, at: $0) }
return nil
- } catch is RefusedOnceHeld {
- return .notAllowed
+ } catch let refused as RefusedOnceHeld {
+ return .notAllowed(refused.refusal)
} catch is NotTheItemThatMoved {
return .missingFromTrash
} catch POSIXError.EEXIST {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
index 99fd07b2..c40b1531 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
@@ -75,12 +75,12 @@ struct AttackRemovalGuardTests {
]
for folder in ["/usr/local/bin", "/usr/local/sbin"] + completions {
let destination = URL(filePath: "\(folder)/\(name)")
- #expect(guardian.allowsPuttingBack(trashedLink, at: destination), "a link can't go back to \(folder)")
- #expect(!guardian.allowsPuttingBack(trashedFile, at: destination), "ATTACK SUCCEEDED: a file can go to \(folder)")
+ #expect(guardian.refusal(ofPuttingBack: trashedLink, at: destination) == nil, "a link can't go back to \(folder)")
+ #expect(guardian.refusal(ofPuttingBack: trashedFile, at: destination) != nil, "ATTACK SUCCEEDED: a file can go to \(folder)")
#expect(!guardian.allowsRemoval(of: destination), "a name with nothing there was allowed in \(folder)")
}
for path in ["/usr/bin/\(name)", "/usr/local/bin/deeper/\(name)", "/usr/local/\(name)", "/usr/local/share/zsh/\(name)"] {
- #expect(!guardian.allowsPuttingBack(trashedLink, at: URL(filePath: path)), "ATTACK SUCCEEDED: a link can go to \(path)")
+ #expect(guardian.refusal(ofPuttingBack: trashedLink, at: URL(filePath: path)) != nil, "ATTACK SUCCEEDED: a link can go to \(path)")
}
#expect(!guardian.allowsRemoval(of: URL(filePath: "/usr/bin/true")))
}
@@ -98,12 +98,12 @@ struct AttackRemovalGuardTests {
let name = "peel-test-\(UUID().uuidString)"
let record = URL(filePath: "/usr/local/Caskroom/\(name)")
- #expect(guardian.allowsPuttingBack(trashedFolder, at: record), "Homebrew's record of a cask can't come back")
- #expect(!guardian.allowsPuttingBack(trashedFile, at: record), "ATTACK SUCCEEDED: a file can go to the Caskroom")
- #expect(!guardian.allowsPuttingBack(trashedLink, at: record), "ATTACK SUCCEEDED: a link can go to the Caskroom")
+ #expect(guardian.refusal(ofPuttingBack: trashedFolder, at: record) == nil, "Homebrew's record of a cask can't come back")
+ #expect(guardian.refusal(ofPuttingBack: trashedFile, at: record) != nil, "ATTACK SUCCEEDED: a file can go to the Caskroom")
+ #expect(guardian.refusal(ofPuttingBack: trashedLink, at: record) != nil, "ATTACK SUCCEEDED: a link can go to the Caskroom")
#expect(!guardian.allowsRemoval(of: record), "a name with nothing there was allowed")
for path in ["/usr/local/Caskroom", "/usr/local/Caskroom/\(name)/1.0", "/usr/local/\(name)", "/usr/Caskroom/\(name)"] {
- #expect(!guardian.allowsPuttingBack(trashedFolder, at: URL(filePath: path)), "ATTACK SUCCEEDED: \(path)")
+ #expect(guardian.refusal(ofPuttingBack: trashedFolder, at: URL(filePath: path)) != nil, "ATTACK SUCCEEDED: \(path)")
}
}
@@ -365,10 +365,10 @@ struct AttackRemovalGuardTests {
// A browser's own data goes with the browser, the folder it reads manifests from included.
#expect(guardian.allowsRemoval(of: home.appending(path: "Library/Application Support/Google/Chrome")))
let avid = home.appending(path: "Library/Application Support/Avid2")
- #expect(guardian.allowsPuttingBack(trashedFolder, at: avid))
+ #expect(guardian.refusal(ofPuttingBack: trashedFolder, at: avid) == nil)
try FileManager.default.moveItem(at: home.appending(path: "Library/Application Support/Avid"), to: avid)
- #expect(guardian.allowsPuttingBack(trashedFolder, at: home.appending(path: "Library/Application Support/Avid")))
- #expect(!guardian.allowsPuttingBack(trashedFile, at: home.appending(path: "Library/Application Support/Avid")))
+ #expect(guardian.refusal(ofPuttingBack: trashedFolder, at: home.appending(path: "Library/Application Support/Avid")) == nil)
+ #expect(guardian.refusal(ofPuttingBack: trashedFile, at: home.appending(path: "Library/Application Support/Avid")) != nil)
}
@Test func theFoldersTheWholeMacShares() throws {
@@ -654,7 +654,7 @@ struct AttackRemovalGuardTests {
#expect(ProtectedData.refuses(url.path(percentEncoded: false), home: homePath), "\(file) is not refused for the helper")
}
}
- #expect(!guardian.allowsPuttingBack(trashed, at: home.appending(path: "Library/Caches/CloudKit")))
+ #expect(guardian.refusal(ofPuttingBack: trashed, at: home.appending(path: "Library/Caches/CloudKit")) != nil)
for file in controls {
#expect(guardian.allowsRemoval(of: home.appending(path: file).deletingLastPathComponent()), "\(file) is refused")
}
@@ -678,7 +678,7 @@ struct AttackRemovalGuardTests {
#expect(guardian.refusal(of: folder) == .inTheCloud)
#expect(guardian.refusal(of: URL(filePath: "/.vol/\(device)/\(number)")) == .inTheCloud, "asked by its numbers")
#expect(guardian.refusal(of: local) == nil)
- #expect(guardian.allowsPuttingBack(trashed, at: home.appending(path: "Desktop/Notes.txt")))
+ #expect(guardian.refusal(ofPuttingBack: trashed, at: home.appending(path: "Desktop/Notes.txt")) == nil)
}
@@ -697,7 +697,7 @@ struct AttackRemovalGuardTests {
#expect(guardian.refusal(of: file.deletingLastPathComponent()) == .inTheCloud)
#expect(guardian.refusal(of: home.appending(path: "Sync", directoryHint: .isDirectory)) == .inTheCloud)
#expect(guardian.refusal(of: twin) == nil)
- #expect(guardian.allowsPuttingBack(trashed, at: file.deletingLastPathComponent().appending(path: "Shells.jpg")))
+ #expect(guardian.refusal(ofPuttingBack: trashed, at: file.deletingLastPathComponent().appending(path: "Shells.jpg")) == nil)
}
/// The guard refuses what is inside a container's `Data/Documents`, where a sandboxed app keeps what its
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index a5473dbe..0f03ca41 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -1205,6 +1205,12 @@ struct CommandLineTests {
#expect(message.contains("See 'peel inventory --help'"))
}
+ @Test func putBackSaysWhyAnItemStays() {
+ #expect(RestoreFailure.notAllowed(.excluded).summary.contains("your exclusions"))
+ #expect(RestoreFailure.notAllowed(.protectedLocation).summary.contains("Finder"))
+ #expect(RestoreFailure.notInATrash.summary == "it isn't in the Trash where Peel put it")
+ }
+
@Test func searchSaysWhatItLeftOutAndWhy() throws {
var results = FileSearchResults()
results.leftOut = [.syncs: 52, .excluded: 1]
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
index 1f0045b8..7a19c1b5 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
@@ -255,7 +255,7 @@ struct ExclusionsTests {
originalURL: applications.appending(path: "Other.app"), trashedURL: other, date: .now
))
- #expect(refusal == .notAllowed)
+ #expect(refusal == .notAllowed(.excluded))
#expect(control == nil)
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift
index dedbf9f5..e0fa0187 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift
@@ -391,8 +391,8 @@ struct SpaceRemovalTests {
let reports = directory.url.appending(path: "home/Library/Logs/DiagnosticReports", directoryHint: .isDirectory)
let removalGuard = RemovalGuard(environment: environment(directory), exclusions: .none)
- #expect(removalGuard.allowsPuttingBack(trashedFolder, at: reports))
- #expect(!removalGuard.allowsPuttingBack(trashedFile, at: reports))
+ #expect(removalGuard.refusal(ofPuttingBack: trashedFolder, at: reports) == nil)
+ #expect(removalGuard.refusal(ofPuttingBack: trashedFile, at: reports) != nil)
}
@Test(.permissionsHold) func whatOnlyAnAdministratorCanMoveGoesThroughTheHelper() async throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
index f54939ef..8faabe92 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
@@ -573,7 +573,7 @@ struct TrashServiceTests {
// Records come from a file on disk, so one naming something that was never in a Trash is refused outright.
let planted = TrashedItem(originalURL: folder, trashedURL: directory.url.appending(path: "payload"), date: .now)
- #expect(await service.restore(planted) == .notAllowed)
+ #expect(await service.restore(planted) == .notInATrash)
}
@Test(.permissionsHold) func saysAtOnceWhatTheHelperKeepsOutOfAFolderCodeIsLoadedFrom() throws {
@@ -700,7 +700,7 @@ struct TrashServiceTests {
]
for source in planted {
let record = TrashedItem(originalURL: directory.url.appending(path: "out/\(source.lastPathComponent)"), trashedURL: source, date: .now)
- #expect(await service.restore(record) == .notAllowed, "\(source.path(percentEncoded: false)) was put back")
+ #expect(await service.restore(record) == .notInATrash, "\(source.path(percentEncoded: false)) was put back")
}
#expect(FileManager.default.fileExists(atPath: secret.path(percentEncoded: false)))
#expect(FileManager.default.fileExists(atPath: thesis.path(percentEncoded: false)))
@@ -771,7 +771,7 @@ struct TrashServiceTests {
let trashed = try directory.file("home/.Trash/x.pdf")
let record = TrashedItem(originalURL: home.appending(path: "Library/Caches/Vendor/x.pdf"), trashedURL: trashed, date: .now)
- #expect(await service.restore(record) == .notAllowed)
+ #expect(await service.restore(record) == .notAllowed(.protectedLocation))
#expect(!FileManager.default.fileExists(atPath: cloud.appending(path: "x.pdf").path(percentEncoded: false)))
#expect(FileManager.default.fileExists(atPath: trashed.path(percentEncoded: false)))
}
diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swift
index a00d6e09..6cdbb5e8 100644
--- a/Peel/Model/RemovalHistoryStore.swift
+++ b/Peel/Model/RemovalHistoryStore.swift
@@ -333,7 +333,7 @@ final class RemovalHistoryStore {
RemovalOutcome.PutBackFailure(url: $0.record.originalURL, failure: $0.failure)
})
// What stayed for a reason that can pass, such as the helper or something in its place, can be asked again.
- let again = stayed.filter { $0.failure != .missingFromTrash && $0.failure != .notAllowed }.map(\.record)
+ let again = stayed.filter { !$0.failure.isFinal }.map(\.record)
if !again.isEmpty { self.undoable = (again, undoable.title) }
}
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index b80a2e55..46de302a 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -249,7 +249,10 @@ extension RestoreFailure {
case .missingFromTrash: String(localized: "It is no longer in the Trash, so there is nothing to put back.")
case .alreadyThere: String(localized: "Something is already there, and Peel never replaces it.")
case .needsHelper: String(localized: "It needs administrator access, which Peel’s helper provides.")
- case .notAllowed: String(localized: "Peel never puts anything back there.")
+ case .notAllowed(.excluded):
+ String(localized: "Your exclusions in Settings keep Peel from putting anything back there. Take it off the list to put this back, or drag it out of the Trash in Finder.")
+ case .notAllowed: String(localized: "Peel protects that place now, so it puts nothing back there. You can drag it out of the Trash in Finder.")
+ case .notInATrash: String(localized: "It isn’t in the Trash where Peel put it, so Peel leaves it where it is.")
case .failed(let message): FixedSentence.translated(message)
}
}