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
A removal that ends with nothing moved or no History record exits 1
Țugui Dragoș4b4f10337c12
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swiftindex 697b088b..8b2aff64 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift@@ -487,13 +487,10 @@ struct UninstallCommand: AsyncParsableCommand {if !recorded {Output.note("Peel couldn't write this to its History, so drag these back out of the Trash in Finder if you need to.")}- guard result.failures.isEmpty else {+ if !result.failures.isEmpty {Self.whatFailed(result, plan: plan, app: target).forEach(Output.note)- throw ExitCode.failure- }- if privacy?.failed == true {- throw ExitCode.failure}+ try Cleanup.end(failed: !result.failures.isEmpty || privacy?.failed == true, recorded: recorded)}/// Returns the notes printed before the question: what the scan couldn't fully check, and files thatdiff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swiftindex a0b3e628..f1b96fae 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift@@ -352,11 +352,9 @@ struct RestoreCommand: AsyncParsableCommand {if !forgotten {Output.note("Peel couldn't write this to its History, so it may offer to put these back again.")}- guard failures.isEmpty else {- for (record, failure) in failures {- Output.note("Couldn't put \(Output.plain(Output.path(record.originalURL))) back: \(failure.summary)")- }- throw ExitCode.failure+ for (record, failure) in failures {+ Output.note("Couldn't put \(Output.plain(Output.path(record.originalURL))) back: \(failure.summary)")}+ try Cleanup.end(failed: !failures.isEmpty, recorded: forgotten)}}diff --git a/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift b/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swiftindex c218762b..198f8ec3 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift@@ -6,7 +6,7 @@ public struct PeelCommand: AsyncParsableCommand {public static let configuration = CommandConfiguration(commandName: "peel",abstract: "Find what apps leave behind and move it to the Trash.",- discussion: "Peel only moves files to the Trash, so you can put them back. Items that need administrator access are left for the Peel app. The tool writes English whatever the Mac's language, since scripts read what it prints. Exit status: 0 when it did what was asked, 1 when something failed or stayed where it was, 2 when you answered no, and 64 when the command or its options are wrong, or when Peel would have to ask and can't (add --yes).",+ discussion: "Peel only moves files to the Trash, so you can put them back. Items that need administrator access are left for the Peel app. The tool writes English whatever the Mac's language, since scripts read what it prints. Exit status: 0 when it did what was asked, 1 when something failed or stayed where it was, or History couldn't record what moved, 2 when you answered no, and 64 when the command or its options are wrong, or when Peel would have to ask and can't (add --yes).",version: Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "",subcommands: [AppsCommand.self,diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swiftindex b7858196..98ee16d1 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift@@ -56,7 +56,8 @@ struct Cleanup {}/// Prints the list, with `notes` under it, and, unless `dryRun` is set, asks, moves what can go, and records it- /// in History. A declined answer exits 2, and a failed move exits 1.+ /// in History. A declined answer exits 2; a failed move, a plan where everything stays, and a move History could+ /// not record exit 1.func run(question: String,notes: [String] = [],@@ -94,6 +95,7 @@ struct Cleanup {if let problem = await refusals.add(refused, source: source, sourceKey: sourceKey, tool: tool) {Output.note(problem.summary)}+ if !refused.isEmpty { throw ExitCode.failure }return}if !yes {@@ -120,11 +122,15 @@ struct Cleanup {if !recorded {Output.note("Peel couldn't write this to its History, so drag these back out of the Trash in Finder if you need to.")}- guard result.failures.isEmpty else {- for failure in result.failures {- Output.note("\(Output.plain(Output.path(failure.url))) stayed: \(failure.reason.summary)")- }- throw ExitCode.failure+ for failure in result.failures {+ Output.note("\(Output.plain(Output.path(failure.url))) stayed: \(failure.reason.summary)")}+ try Self.end(failed: !result.failures.isEmpty, recorded: recorded)+ }++ /// 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 {+ guard !failed, recorded else { throw ExitCode.failure }}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swiftindex 60672862..a127eadc 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift@@ -157,22 +157,43 @@ struct CleanupTests {#expect(FileManager.default.fileExists(atPath: cache.path(percentEncoded: false)))}- /// A plan with nothing to move is not a failure. Its refusals are still recorded, since a removal where- /// everything stayed is exactly what the refusal log is for.- @Test func nothingToMoveIsNoFailureAndIsWrittenDown() async throws {+ /// A plan where everything stays exits 1, as `peel uninstall` does when its app stays, and as the tool's help+ /// says of anything that stayed where it was. Its refusals are still recorded, since a removal where everything+ /// stayed is exactly what the refusal log is for.+ @Test func whenEverythingStaysTheRemovalFailsAndIsWrittenDown() async throws {let directory = try TemporaryDirectory()let documents = try directory.directory("home/Documents")let log = RemovalLog(url: directory.url.appending(path: "Peel/removals.json"))let refusals = RefusalLog(url: directory.url.appending(path: "Peel/refusals.json"))let plan = cleanup(items: [(documents, nil)], service: try service(in: directory))- try await plan.run(question: "?", dryRun: false, yes: true, using: try service(in: directory), recordingIn: log, refusals: refusals)+ await #expect(throws: ExitCode.failure) {+ try await plan.run(+ question: "?", dryRun: false, yes: true, using: try service(in: directory),+ recordingIn: log, refusals: refusals+ )+ }#expect(await RemovalLog(url: log.url).load().records?.isEmpty == true)#expect(await RefusalLog(url: refusals.url).load().records.map(\.reason) == ["stays-in-place"])#expect(FileManager.default.fileExists(atPath: documents.path(percentEncoded: false)))}+ /// What moved is only in the Trash when History cannot be written, so the removal ends as one that failed.+ @Test func aRemovalHistoryCannotRecordFails() async throws {+ let directory = try TemporaryDirectory()+ let cache = try directory.file("home/Library/Caches/com.example.editor/blob", bytes: 20)+ try directory.file("Peel", bytes: 1)+ let log = RemovalLog(url: directory.url.appending(path: "Peel/removals.json"))+ let service = try service(in: directory)+ let plan = cleanup(items: [(cache, 20)], service: service)++ await #expect(throws: ExitCode.failure) {+ try await plan.run(question: "?", dryRun: false, yes: true, using: service, recordingIn: log)+ }+ #expect(!FileManager.default.fileExists(atPath: cache.path(percentEncoded: false)))+ }+/// A dry run changes nothing, not even the refusal log.@Test func aDryRunWritesNothingDownEither() async throws {let directory = try TemporaryDirectory()diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swiftindex 1a42353a..58bb4750 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift@@ -266,7 +266,8 @@ struct FileCommandTests {#expect(FileManager.default.fileExists(atPath: other.items[0].url.path(percentEncoded: false)))}- /// The command line never uses the helper, so what needs administrator access stays and is recorded as refused.+ /// The command line never uses the helper, so what needs administrator access stays, is recorded as refused,+ /// and, since nothing else moved, the command exits 1.@Test func leavesWhatNeedsAdministratorAccessAndSaysSo() async throws {let directory = try TemporaryDirectory()let logs = logs(in: directory)@@ -274,9 +275,14 @@ struct FileCommandTests {try orphan("com.example.gone", in: directory, requiresPrivileges: true),])let scan = OrphanScan(groups: [group], unreadableLocations: [])+ let service = try service(in: directory)- try await (command(["orphans", "--remove", "com.example.gone", "-y"]) as OrphansCommand)- .clean("com.example.gone", in: scan, apps: [], scanner: scanner(in: directory), using: try service(in: directory), recordingIn: logs.removals, refusals: logs.refusals)+ await #expect(throws: ExitCode.failure) {+ try await (command(["orphans", "--remove", "com.example.gone", "-y"]) as OrphansCommand).clean(+ "com.example.gone", in: scan, apps: [], scanner: scanner(in: directory), using: service,+ recordingIn: logs.removals, refusals: logs.refusals+ )+ }#expect(await moved(logs).isEmpty)#expect(await logs.refusals.load().records.map(\.reason) == ["needs-helper"])diff --git a/Support/peel.1 b/Support/peel.1index d528d74a..bd908783 100644--- a/Support/peel.1+++ b/Support/peel.1@@ -1,5 +1,5 @@.\" "Generated by swift-argument-parser"-.Dd September 27, 2026+.Dd September 28, 2026.Dt PEEL 1.Os.Sh NAME@@ -11,7 +11,7 @@.Op Fl -version.Op Fl -help.Sh DESCRIPTION-Peel only moves files to the Trash, so you can put them back. Items that need administrator access are left for the Peel app. The tool writes English whatever the Mac's language, since scripts read what it prints. Exit status: 0 when it did what was asked, 1 when something failed or stayed where it was, 2 when you answered no, and 64 when the command or its options are wrong, or when Peel would have to ask and can't (add --yes).+Peel only moves files to the Trash, so you can put them back. Items that need administrator access are left for the Peel app. The tool writes English whatever the Mac's language, since scripts read what it prints. Exit status: 0 when it did what was asked, 1 when something failed or stayed where it was, or History couldn't record what moved, 2 when you answered no, and 64 when the command or its options are wrong, or when Peel would have to ask and can't (add --yes)..Bl -tag -width 6n.It Fl -versionShow the version.@@ -307,7 +307,7 @@ Show help information..It Em updatesCheck installed apps for updates..Pp-Peel reads the settings of the Peel app: which source it prefers, which apps it was told to leave alone, and which versions were skipped. Nothing is installed; apps with no feed are left out.+Peel reads the settings of the Peel app: which source it prefers, which apps it was told to leave alone, and which versions were skipped. Nothing is installed; apps with no feed are left out unless --all is given..Bl -tag -width 6n.It Fl -allShow every app, not only those with an update.