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.

Move a reset's copy of settings to the Trash when the app opened before anything moved

Țugui Dragoș952ca528d605
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 978753fc..75878a4d 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -372,7 +372,8 @@ macOS asks the user to approve it once. It talks to the app over XPC.
- **Resetting an app.** `AppReset` selects an app's settings, caches, and window state, which the app makes again
when it next opens, and offers its website data and the data it keeps for the person without selecting them. It
never offers the app itself, only files certainly the app's that nothing else claims, and it saves each preference
- domain first (`PreferenceBackup`): a reset whose copy fails moves nothing.
+ domain first (`PreferenceBackup`): a reset whose copy fails moves nothing, and one that finds the app open once the
+ copy is made moves nothing either and puts that copy in the Trash.
- **Watching the Trash.** `TrashMonitor` notices an app the user moves to the Trash: the home's, and the Trash of
each other disk Peel lists apps on (`VolumeTrashes`), where an app thrown away from that disk lands. `TrashService`
tells it about Peel's own moves (`OwnTrashMoves`), by where each item landed, so Peel never offers to clean up
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift b/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift
index 034969e4..5d0f6c53 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift
@@ -99,7 +99,8 @@ public struct AppReset: Sendable {
/// Copies the settings in `selection`, asks again whether the app is open, since the copy takes a moment, then
/// moves the selection to the Trash and resets the privacy permissions when asked. Nothing starts while every move
- /// would be refused, and nothing moves when the copy fails or the app opened meanwhile, the copy then staying.
+ /// would be refused, and nothing moves when the copy fails or the app opened meanwhile. In the second case the copy
+ /// goes to the Trash, since no reset happened that it could undo.
@concurrent
public func run(
_ selection: Set<URL>,
@@ -147,6 +148,9 @@ public struct AppReset: Sendable {
break
}
guard await !isOpen() else {
+ if let backup = outcome.backup, await service.trashOwnFiles([backup]).failures.isEmpty {
+ outcome.backup = nil
+ }
outcome.stop = .appOpened
return outcome
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift
index a5cccc5a..cdf44382 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift
@@ -392,7 +392,7 @@ struct AppResetTests {
)
#expect(outcome.stop == .appOpened)
- #expect(outcome.backup == copy)
+ #expect(outcome.backup == nil && !copy.isThere, "a copy stood in Saved Settings for a reset that didn't happen")
#expect(outcome.result.trashed.isEmpty)
#expect(!asked.withLock { $0 })
#expect(settings.isThere)