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 what an app already in the Trash left behind in peel uninstall

Țugui Dragoș3b7f5ea88756
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index 638d56df..427b7967 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -709,7 +709,7 @@ struct UninstallCommand: AsyncParsableCommand {
}
return
}
- if !yes {
+ if !yes, !plan.moving.isEmpty {
let items = Output.count(plan.moving.count, "item", "items")
try Output.confirm(resetPrivacy ? "Reset privacy permissions and move \(items) to the Trash?" : "Move \(items) to the Trash?")
}
@@ -741,7 +741,9 @@ struct UninstallCommand: AsyncParsableCommand {
Output.note(privacy.line)
}
} else {
- Output.line("Moved \(Output.count(result.trashed.count, "item", "items")) to the Trash.")
+ if !plan.moving.isEmpty {
+ Output.line("Moved \(Output.count(result.trashed.count, "item", "items")) to the Trash.")
+ }
if let privacy {
privacy.failed ? Output.note(privacy.line) : Output.line(privacy.line)
}
@@ -759,7 +761,10 @@ struct UninstallCommand: AsyncParsableCommand {
if !result.failures.isEmpty {
Self.whatFailed(result, plan: plan, app: target).forEach(Output.note)
}
- try Cleanup.end(failed: !result.failures.isEmpty || privacy?.failed == true, recorded: recorded)
+ let everythingStayed = plan.moving.isEmpty && !plan.staying.isEmpty
+ try Cleanup.end(
+ failed: !result.failures.isEmpty || privacy?.failed == true || everythingStayed, recorded: recorded
+ )
}
/// Returns the notes printed before the question: what the scan couldn't fully check, files that will stay, and
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
index 4235b9e1..09cec63d 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
@@ -101,13 +101,13 @@ struct UninstallPlan {
}
/// Moves the bundle to the Trash on its own, then the rest only if the bundle really moved. When the app itself
- /// stays, nothing moves.
+ /// stays, nothing moves. An app already in the Trash isn't in the plan, and its files move on their own.
func move(using service: TrashService) async -> TrashResult {
+ guard appStays == nil else { return TrashResult() }
let urls = moving.map(\.url)
- guard urls.contains(app) else { return TrashResult() }
let files = urls.filter { $0 != app }
return await service.trash(
- apps: [app],
+ apps: urls.filter { $0 == app },
thenFiles: { stayed in stayed.isEmpty ? files : [] },
usingHelperFor: [],
lettingTheirProgramsRun: uninstallsItself ? [app] : [],
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift
index 73ef7db9..0d2e4cb0 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift
@@ -289,6 +289,21 @@ struct CleanupTests {
#expect(records.count == 3)
}
+ @Test func anUninstallMovesWhatAnAppAlreadyInTheTrashLeftBehind() async throws {
+ let directory = try TemporaryDirectory()
+ let app = try directory.directory("home/.Trash/Editor.app")
+ let data = try directory.directory("home/Library/Caches/org.example.editor")
+ let plan = UninstallPlan(app: app, items: [
+ UninstallPlan.Item(url: data, size: 64, refusal: nil),
+ ], needsAdministrator: 0, needsReview: 0)
+
+ let result = await plan.move(using: try service(in: directory))
+
+ #expect(result.trashed.map(\.originalURL.lastPathComponent) == ["org.example.editor"])
+ #expect(result.failures.isEmpty)
+ #expect(app.isThere)
+ }
+
@Test func anUninstallRecordsThatTheAppSharedItsStorage() async throws {
let directory = try TemporaryDirectory()
let app = try directory.directory("home/Applications/Twin.app")