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.

Count what needs review the same with and without --all in peel leftovers

Țugui Dragoș1eedd66fa8b4
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index 6b304e28..ceccdd33 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -151,13 +151,12 @@ struct LeftoversCommand: AsyncParsableCommand {
let appStays: String?
init(
- app: InstalledApp, appSize: Int64?, leftovers: [Leftover], needsReview: Int, scan: LeftoverScan,
- appStays: String?
+ app: InstalledApp, appSize: Int64?, leftovers: [Leftover], scan: LeftoverScan, appStays: String?
) {
self.app = AppRecord(app)
self.appSize = appSize
self.leftovers = leftovers.map(LeftoverRecord.init)
- self.needsReview = needsReview
+ needsReview = scan.leftovers.count { !$0.match.isRecommended }
unreadableLocations = scan.unreadableLocations.map { Output.path($0.url) }
needsFullDiskAccess = scan.needsFullDiskAccess
cutShortLocations = scan.cutShortLocations.map { Output.path($0.url) }
@@ -219,7 +218,7 @@ struct LeftoversCommand: AsyncParsableCommand {
if output.json {
let appSize = uninstallation.isAppMeasured ? uninstallation.appSize : nil
let report = Report(
- app: target, appSize: appSize, leftovers: leftovers, needsReview: hidden, scan: uninstallation.scan,
+ app: target, appSize: appSize, leftovers: leftovers, scan: uninstallation.scan,
appStays: stays?.description
)
try Output.json(report)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index 1c4be586..869b509e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -91,7 +91,7 @@ struct CommandLineTests {
let report = { (stays: String?) throws -> [String: Any] in
let leftovers = LeftoversCommand.Report(
- app: notes, appSize: nil, leftovers: [cache], needsReview: 0,
+ app: notes, appSize: nil, leftovers: [cache],
scan: LeftoverScan(leftovers: [], unreadableLocations: []), appStays: stays
)
let json = try Output.jsonText(leftovers)
@@ -587,6 +587,25 @@ struct CommandLineTests {
#expect(collected.notes.contains(folder.path(percentEncoded: false)))
}
+ @Test func theLeftoversReportCountsWhatNeedsReviewWhetherOrNotItIsListed() throws {
+ let app = InstalledApp(
+ url: URL(filePath: "/Applications/Editor.app", directoryHint: .isDirectory),
+ bundleIdentifier: "org.example.editor", name: "Editor"
+ )
+ let review = leftover(URL(filePath: "/Users/me/Library/Caches/review"), heldBack: .namedLikeTheApp)
+ let scan = LeftoverScan(leftovers: [review], unreadableLocations: [])
+
+ for listed in [[], [review]] {
+ let report = LeftoversCommand.Report(
+ app: app, appSize: nil, leftovers: listed, scan: scan, appStays: nil
+ )
+ let json = try #require(
+ JSONSerialization.jsonObject(with: Data(try Output.jsonText(report).utf8)) as? [String: Any]
+ )
+ #expect(json["needsReview"] as? Int == 1)
+ }
+ }
+
/// `peel leftovers --json` names the folders macOS kept Peel out of, where the app may have left more.
@Test func theLeftoversReportSaysWhereItCouldNotLook() throws {
let app = InstalledApp(url: URL(filePath: "/Applications/Editor.app", directoryHint: .isDirectory), bundleIdentifier: "com.example.editor", name: "Editor")
@@ -596,13 +615,12 @@ struct CommandLineTests {
leftovers: [], unreadableLocations: [unread], cutShortLocations: [unread], needsFullDiskAccess: true
)
let report = LeftoversCommand.Report(
- app: app, appSize: nil, leftovers: [], needsReview: 3, scan: scan, appStays: nil
+ app: app, appSize: nil, leftovers: [], scan: scan, appStays: nil
)
let json = try #require(
JSONSerialization.jsonObject(with: Data(try Output.jsonText(report).utf8)) as? [String: Any]
)
- #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)