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.

peel uninstall says when it reset the permissions of an app that stayed

Țugui Dragoș43988509a8df
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index a1fb4012..04970728 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -261,6 +261,8 @@ struct UninstallCommand: AsyncParsableCommand {
let failed: [Failure]
/// Whether the privacy permissions were reset, or `null` when that wasn't asked for or it was a dry run.
let privacyReset: Bool?
+ /// Whether the app itself went to the Trash, or `null` for a dry run.
+ let appMoved: Bool?
let needsAdministrator: Int
let needsReview: Int
let unreadableLocations: [String]
@@ -272,12 +274,13 @@ struct UninstallCommand: AsyncParsableCommand {
case moved
case failed
case privacyReset
+ case appMoved
case needsAdministrator
case needsReview
case unreadableLocations
}
- /// Encodes an unknown `privacyReset` as `null`, for the reason `AppRecord` gives.
+ /// Encodes an unknown `privacyReset` and `appMoved` as `null`, for the reason `AppRecord` gives.
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(app, forKey: .app)
@@ -286,6 +289,7 @@ struct UninstallCommand: AsyncParsableCommand {
try container.encode(moved, forKey: .moved)
try container.encode(failed, forKey: .failed)
try container.encode(privacyReset, forKey: .privacyReset)
+ try container.encode(appMoved, forKey: .appMoved)
try container.encode(needsAdministrator, forKey: .needsAdministrator)
try container.encode(needsReview, forKey: .needsReview)
try container.encode(unreadableLocations, forKey: .unreadableLocations)
@@ -311,6 +315,7 @@ struct UninstallCommand: AsyncParsableCommand {
Report.Failure(path: Output.path($0.url), reason: $0.reason.name, detail: $0.reason.detail)
},
privacyReset: privacy.map { $0 == .reset },
+ appMoved: result.map { result in result.trashed.contains { $0.originalURL == plan.app } },
needsAdministrator: plan.needsAdministrator,
needsReview: plan.needsReview,
unreadableLocations: unreadable.map { Output.path($0.url) }
@@ -348,11 +353,18 @@ struct UninstallCommand: AsyncParsableCommand {
throw CommandFailure("Peel never resets privacy permissions for \(Output.plain(target.name)). Leave out --reset-privacy to remove it anyway.")
}
- /// Returns the line that reports the privacy reset, and whether the command fails because of it.
- static func privacyOutcome(_ result: PrivacyReset.Result, app: InstalledApp) -> (line: String, failed: Bool) {
- result == .reset
- ? ("Reset \(Output.plain(app.name))'s privacy permissions.", false)
- : ("\(Output.plain(app.name))'s privacy permissions weren't reset: \(result.summary).", true)
+ /// Returns the line that reports the privacy reset, and whether it is a warning the command fails with: a reset
+ /// that did not happen, or one for an app that then stayed (`PrivacyReset.worthTelling`).
+ static func privacyOutcome(
+ _ result: PrivacyReset.Result, app: InstalledApp, after removal: TrashResult
+ ) -> (line: String, failed: Bool) {
+ let name = Output.plain(app.name)
+ guard result == .reset else { return ("\(name)'s privacy permissions weren't reset: \(result.summary).", true) }
+ guard PrivacyReset.worthTelling([(app, result)], after: removal).isEmpty else {
+ let stayed = "\(name) stayed where it is, so it will ask for them again"
+ return ("Reset \(name)'s privacy permissions, but \(stayed).", true)
+ }
+ return ("Reset \(name)'s privacy permissions.", false)
}
func run() async throws {
@@ -428,7 +440,7 @@ struct UninstallCommand: AsyncParsableCommand {
let sizes = [URL: Int64](measured: plan.items.map { ($0.url, $0.size) })
return (reset, result, await Removals.record(result, from: target.name, sizes: sizes, tool: "applications"))
}
- let privacy = reset.map { Self.privacyOutcome($0, app: target) }
+ let privacy = reset.map { Self.privacyOutcome($0, app: target, after: result) }
if output.json {
let report = Self.report(app: target, plan: plan, result: result, privacy: reset, unreadable: unreadable)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index c63d3981..03fcd601 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -301,6 +301,7 @@ struct CommandLineTests {
#expect(failed.first?["detail"] as? String == "disk full")
#expect(report["dryRun"] as? Bool == false)
#expect(report["privacyReset"] as? Bool == true)
+ #expect(report["appMoved"] as? Bool == false)
#expect(report["needsAdministrator"] as? Int == 1)
#expect(report["needsReview"] as? Int == 2)
#expect(report["unreadableLocations"] as? [String] == [])
@@ -310,6 +311,7 @@ struct CommandLineTests {
#expect(planned["dryRun"] as? Bool == true)
#expect(planned["moved"] as? [String] == [])
#expect(planned["privacyReset"] is NSNull)
+ #expect(planned["appMoved"] is NSNull)
}
/// A script adds sizes up, so an unknown size is `null` under the same key: never zero, and never a missing
@@ -582,11 +584,16 @@ struct CommandLineTests {
@Test func saysWhatCameOfThePrivacyReset() {
let editor = InstalledApp(url: URL(filePath: "/Applications/Editor.app", directoryHint: .isDirectory), bundleIdentifier: "com.example.editor", name: "Editor")
- #expect(UninstallCommand.privacyOutcome(.reset, app: editor) == ("Reset Editor's privacy permissions.", false))
- #expect(UninstallCommand.privacyOutcome(.notKnownToTheSystem, app: editor) == ("Editor's privacy permissions weren't reset: macOS couldn't find the app.", true))
- #expect(UninstallCommand.privacyOutcome(.failed(""), app: editor) == ("Editor's privacy permissions weren't reset: macOS didn't say why.", true))
- #expect(UninstallCommand.privacyOutcome(.failed("Failed to reset All"), app: editor) == ("Editor's privacy permissions weren't reset: macOS reported: Failed to reset All.", true))
- #expect(UninstallCommand.privacyOutcome(.couldNotAsk("tccutil didn't answer in time"), app: editor) == ("Editor's privacy permissions weren't reset: tccutil didn't answer in time.", true))
+ let trashed = TrashedItem(originalURL: editor.url, trashedURL: editor.url, date: .now)
+ let moved = TrashResult(trashed: [trashed], failures: [])
+ let stayed = TrashResult(trashed: [], failures: [TrashFailure(url: editor.url, reason: .notPermitted)])
+
+ #expect(UninstallCommand.privacyOutcome(.reset, app: editor, after: moved) == ("Reset Editor's privacy permissions.", false))
+ #expect(UninstallCommand.privacyOutcome(.reset, app: editor, after: stayed) == ("Reset Editor's privacy permissions, but Editor stayed where it is, so it will ask for them again.", true))
+ #expect(UninstallCommand.privacyOutcome(.notKnownToTheSystem, app: editor, after: moved) == ("Editor's privacy permissions weren't reset: macOS couldn't find the app.", true))
+ #expect(UninstallCommand.privacyOutcome(.failed(""), app: editor, after: moved) == ("Editor's privacy permissions weren't reset: macOS didn't say why.", true))
+ #expect(UninstallCommand.privacyOutcome(.failed("Failed to reset All"), app: editor, after: moved) == ("Editor's privacy permissions weren't reset: macOS reported: Failed to reset All.", true))
+ #expect(UninstallCommand.privacyOutcome(.couldNotAsk("tccutil didn't answer in time"), app: editor, after: moved) == ("Editor's privacy permissions weren't reset: tccutil didn't answer in time.", true))
}
/// Nothing moves without an answer. Where `peel` cannot ask, it needs `--yes` or `--dry-run`, which leave