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.

Name what wasn't read to the end in the JSON of leftovers and uninstall

Țugui Dragoș5d0abb8242e2
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index f56e65fc..638d56df 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -144,19 +144,23 @@ struct LeftoversCommand: AsyncParsableCommand {
let leftovers: [LeftoverRecord]
let needsReview: Int
let unreadableLocations: [String]
+ let needsFullDiskAccess: Bool
+ let cutShortLocations: [String]
/// Why `peel uninstall` would leave the app itself where it is, or `null` when it would move it. While the app
/// stays, none of its files moves.
let appStays: String?
init(
- app: InstalledApp, appSize: Int64?, leftovers: [Leftover], needsReview: Int,
- unreadableLocations: [SearchLocation], appStays: String?
+ app: InstalledApp, appSize: Int64?, leftovers: [Leftover], needsReview: Int, scan: LeftoverScan,
+ appStays: String?
) {
self.app = AppRecord(app)
self.appSize = appSize
self.leftovers = leftovers.map(LeftoverRecord.init)
self.needsReview = needsReview
- self.unreadableLocations = unreadableLocations.map { Output.path($0.url) }
+ unreadableLocations = scan.unreadableLocations.map { Output.path($0.url) }
+ needsFullDiskAccess = scan.needsFullDiskAccess
+ cutShortLocations = scan.cutShortLocations.map { Output.path($0.url) }
self.appStays = appStays
}
@@ -166,6 +170,8 @@ struct LeftoversCommand: AsyncParsableCommand {
case leftovers
case needsReview
case unreadableLocations
+ case needsFullDiskAccess
+ case cutShortLocations
case appStays
}
@@ -176,6 +182,8 @@ struct LeftoversCommand: AsyncParsableCommand {
try container.encode(leftovers, forKey: .leftovers)
try container.encode(needsReview, forKey: .needsReview)
try container.encode(unreadableLocations, forKey: .unreadableLocations)
+ try container.encode(needsFullDiskAccess, forKey: .needsFullDiskAccess)
+ try container.encode(cutShortLocations, forKey: .cutShortLocations)
try container.encode(appStays, forKey: .appStays)
}
}
@@ -210,9 +218,8 @@ struct LeftoversCommand: AsyncParsableCommand {
Self.notes(uninstallation, homebrew: homebrew, hidden: leftovers.isEmpty && !output.json ? 0 : hidden)
if output.json {
let appSize = uninstallation.isAppMeasured ? uninstallation.appSize : nil
- let unread = uninstallation.scan.unreadableLocations
let report = Report(
- app: target, appSize: appSize, leftovers: leftovers, needsReview: hidden, unreadableLocations: unread,
+ app: target, appSize: appSize, leftovers: leftovers, needsReview: hidden, scan: uninstallation.scan,
appStays: stays?.description
)
try Output.json(report)
@@ -363,6 +370,8 @@ struct UninstallCommand: AsyncParsableCommand {
let needsReview: Int
let leftForAnAdministrator: Int
let unreadableLocations: [String]
+ let needsFullDiskAccess: Bool
+ let cutShortLocations: [String]
let shellReferences: [ShellReference]
struct ShellReference: Encodable {
@@ -382,6 +391,8 @@ struct UninstallCommand: AsyncParsableCommand {
case needsReview
case leftForAnAdministrator
case unreadableLocations
+ case needsFullDiskAccess
+ case cutShortLocations
case shellReferences
}
@@ -399,6 +410,8 @@ struct UninstallCommand: AsyncParsableCommand {
try container.encode(needsReview, forKey: .needsReview)
try container.encode(leftForAnAdministrator, forKey: .leftForAnAdministrator)
try container.encode(unreadableLocations, forKey: .unreadableLocations)
+ try container.encode(needsFullDiskAccess, forKey: .needsFullDiskAccess)
+ try container.encode(cutShortLocations, forKey: .cutShortLocations)
try container.encode(shellReferences, forKey: .shellReferences)
}
}
@@ -409,7 +422,7 @@ struct UninstallCommand: AsyncParsableCommand {
plan: UninstallPlan,
result: TrashResult?,
privacy: PrivacyReset.Result?,
- unreadable: [SearchLocation],
+ scan: LeftoverScan,
shellReferences: [ShellReferences.Reference] = []
) -> Report {
Report(
@@ -427,7 +440,9 @@ struct UninstallCommand: AsyncParsableCommand {
needsAdministrator: plan.needsAdministrator,
needsReview: plan.needsReview,
leftForAnAdministrator: plan.leftForAnAdministrator,
- unreadableLocations: unreadable.map { Output.path($0.url) },
+ unreadableLocations: scan.unreadableLocations.map { Output.path($0.url) },
+ needsFullDiskAccess: scan.needsFullDiskAccess,
+ cutShortLocations: scan.cutShortLocations.map { Output.path($0.url) },
shellReferences: shellReferences.map { Report.ShellReference(file: Output.path($0.file), line: $0.line) }
)
}
@@ -665,7 +680,6 @@ struct UninstallCommand: AsyncParsableCommand {
}
throw CommandFailure("Peel won't move \(Output.plain(Output.path(target.url))): \(refusal.summary). Nothing of \(Output.plain(target.name)) was touched.")
}
- let unreadable = uninstallation.scan.unreadableLocations
if !output.json {
// The third column appears only when some item stays, so an ordinary list has no trailing spaces.
let staying = !plan.staying.isEmpty
@@ -688,7 +702,8 @@ struct UninstallCommand: AsyncParsableCommand {
guard !dryRun else {
if output.json {
- try Output.json(Self.report(app: target, plan: plan, result: nil, privacy: nil, unreadable: unreadable))
+ let scan = uninstallation.scan
+ try Output.json(Self.report(app: target, plan: plan, result: nil, privacy: nil, scan: scan))
} else {
Output.line(resetPrivacy ? "Dry run: nothing was moved or reset." : "Dry run: nothing was moved.")
}
@@ -718,7 +733,7 @@ struct UninstallCommand: AsyncParsableCommand {
if output.json {
let report = Self.report(
- app: target, plan: plan, result: result, privacy: reset, unreadable: unreadable,
+ app: target, plan: plan, result: result, privacy: reset, scan: uninstallation.scan,
shellReferences: references
)
try Output.json(report)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index 0200f381..f9ac1f65 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -91,7 +91,8 @@ struct CommandLineTests {
let report = { (stays: String?) throws -> [String: Any] in
let leftovers = LeftoversCommand.Report(
- app: notes, appSize: nil, leftovers: [cache], needsReview: 0, unreadableLocations: [], appStays: stays
+ app: notes, appSize: nil, leftovers: [cache], needsReview: 0,
+ scan: LeftoverScan(leftovers: [], unreadableLocations: []), appStays: stays
)
let json = try Output.jsonText(leftovers)
return try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])
@@ -547,8 +548,11 @@ struct CommandLineTests {
let app = InstalledApp(url: URL(filePath: "/Applications/Editor.app", directoryHint: .isDirectory), bundleIdentifier: "com.example.editor", name: "Editor")
let unread = SearchLocation(kind: .containers, url: URL(filePath: "/Users/me/Library/Containers", directoryHint: .isDirectory))
+ let scan = LeftoverScan(
+ leftovers: [], unreadableLocations: [unread], cutShortLocations: [unread], needsFullDiskAccess: true
+ )
let report = LeftoversCommand.Report(
- app: app, appSize: nil, leftovers: [], needsReview: 3, unreadableLocations: [unread], appStays: nil
+ app: app, appSize: nil, leftovers: [], needsReview: 3, scan: scan, appStays: nil
)
let json = try #require(
@@ -556,6 +560,8 @@ struct CommandLineTests {
)
#expect(json["needsReview"] as? Int == 3)
#expect(json["unreadableLocations"] as? [String] == ["/Users/me/Library/Containers"])
+ #expect(json["cutShortLocations"] as? [String] == ["/Users/me/Library/Containers"])
+ #expect(json["needsFullDiskAccess"] as? Bool == true)
#expect(json["appSize"] is NSNull)
}
@@ -585,9 +591,10 @@ struct CommandLineTests {
], needsAdministrator: 1, needsReview: 2)
let result = TrashResult(trashed: [], failures: [TrashFailure(url: support, reason: .failed("disk full"))])
let editor = InstalledApp(url: app, bundleIdentifier: "com.example.editor", name: "Editor")
+ let nothing = LeftoverScan(leftovers: [], unreadableLocations: [])
let json = try Output.jsonText(
- UninstallCommand.report(app: editor, plan: plan, result: result, privacy: .reset, unreadable: [])
+ UninstallCommand.report(app: editor, plan: plan, result: result, privacy: .reset, scan: nothing)
)
let report = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])
@@ -604,10 +611,12 @@ struct CommandLineTests {
#expect(report["needsAdministrator"] as? Int == 1)
#expect(report["needsReview"] as? Int == 2)
#expect(report["unreadableLocations"] as? [String] == [])
+ #expect(report["needsFullDiskAccess"] as? Bool == false)
+ #expect(report["cutShortLocations"] as? [String] == [])
#expect((report["shellReferences"] as? [Any])?.isEmpty == true)
let named = try Output.jsonText(UninstallCommand.report(
- app: editor, plan: plan, result: result, privacy: nil, unreadable: [],
+ app: editor, plan: plan, result: result, privacy: nil, scan: nothing,
shellReferences: [ShellReferences.Reference(file: URL(filePath: "/Users/me/.zshrc"), line: 12)]
))
let shell = try #require(JSONSerialization.jsonObject(with: Data(named.utf8)) as? [String: Any])
@@ -615,10 +624,16 @@ struct CommandLineTests {
#expect(references.map { $0["file"] as? String } == ["/Users/me/.zshrc"])
#expect(references.map { $0["line"] as? Int } == [12])
+ let containers = SearchLocation(kind: .containers, url: URL(filePath: "/Users/me/Library/Containers"))
+ let cutShort = LeftoverScan(
+ leftovers: [], unreadableLocations: [containers], cutShortLocations: [containers], needsFullDiskAccess: true
+ )
let dryRun = try Output.jsonText(
- UninstallCommand.report(app: editor, plan: plan, result: nil, privacy: nil, unreadable: [])
+ UninstallCommand.report(app: editor, plan: plan, result: nil, privacy: nil, scan: cutShort)
)
let planned = try #require(JSONSerialization.jsonObject(with: Data(dryRun.utf8)) as? [String: Any])
+ #expect(planned["needsFullDiskAccess"] as? Bool == true)
+ #expect(planned["cutShortLocations"] as? [String] == ["/Users/me/Library/Containers"])
#expect(planned["dryRun"] as? Bool == true)
#expect(planned["moved"] as? [String] == [])
#expect(planned["privacyReset"] is NSNull)
@@ -797,7 +812,10 @@ struct CommandLineTests {
])
#expect(UninstallPlan.make(editor, keepLeftovers: true, refusal: { _ in nil }).leftForAnAdministrator == 1)
let json = try Output.jsonText(
- UninstallCommand.report(app: app, plan: plan, result: nil, privacy: nil, unreadable: [])
+ UninstallCommand.report(
+ app: app, plan: plan, result: nil, privacy: nil,
+ scan: LeftoverScan(leftovers: [], unreadableLocations: [])
+ )
)
let report = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])
#expect(report["leftForAnAdministrator"] as? Int == 1)