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
Say what is hidden when peel leftovers lists nothing
Țugui Dragoș83833d6178ae
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swiftindex 31328948..f56e65fc 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift@@ -142,18 +142,20 @@ struct LeftoversCommand: AsyncParsableCommand {/// finds the key.let appSize: Int64?let leftovers: [LeftoverRecord]+ let needsReview: Intlet unreadableLocations: [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], unreadableLocations: [SearchLocation],- appStays: String?+ app: InstalledApp, appSize: Int64?, leftovers: [Leftover], needsReview: Int,+ unreadableLocations: [SearchLocation], appStays: String?) {self.app = AppRecord(app)self.appSize = appSizeself.leftovers = leftovers.map(LeftoverRecord.init)+ self.needsReview = needsReviewself.unreadableLocations = unreadableLocations.map { Output.path($0.url) }self.appStays = appStays}@@ -162,6 +164,7 @@ struct LeftoversCommand: AsyncParsableCommand {case appcase appSizecase leftovers+ case needsReviewcase unreadableLocationscase appStays}@@ -171,6 +174,7 @@ struct LeftoversCommand: AsyncParsableCommand {try container.encode(app, forKey: .app)try container.encode(appSize, forKey: .appSize)try container.encode(leftovers, forKey: .leftovers)+ try container.encode(needsReview, forKey: .needsReview)try container.encode(unreadableLocations, forKey: .unreadableLocations)try container.encode(appStays, forKey: .appStays)}@@ -202,12 +206,13 @@ struct LeftoversCommand: AsyncParsableCommand {if uninstallation.isAppInTheTrash {Output.note(Self.inTheTrash(target))}- Self.notes(uninstallation, homebrew: homebrew, hidden: uninstallation.scan.leftovers.count - leftovers.count)+ let hidden = uninstallation.scan.leftovers.count - leftovers.count+ Self.notes(uninstallation, homebrew: homebrew, hidden: leftovers.isEmpty && !output.json ? 0 : hidden)if output.json {let appSize = uninstallation.isAppMeasured ? uninstallation.appSize : nillet unread = uninstallation.scan.unreadableLocationslet report = Report(- app: target, appSize: appSize, leftovers: leftovers, unreadableLocations: unread,+ app: target, appSize: appSize, leftovers: leftovers, needsReview: hidden, unreadableLocations: unread,appStays: stays?.description)try Output.json(report)@@ -216,13 +221,19 @@ struct LeftoversCommand: AsyncParsableCommand {let appSize = uninstallation.isAppMeasured ? Output.size(uninstallation.appSize) : "unknown"Output.line("\(target.name) \(target.version ?? "") \(appSize) \(Output.path(target.url))")if leftovers.isEmpty {- Output.line("No leftovers found.")+ Output.line(Self.whenNothingIsShown(hidden: hidden))} else {Output.line()Output.table(leftovers.map { [Output.size(Self.measured($0)), Output.path($0.url), Self.summary(of: $0)] })}}+ static func whenNothingIsShown(hidden: Int) -> String {+ guard hidden > 0 else { return "No leftovers found." }+ let them = hidden == 1 ? "it" : "them"+ return "No leftovers Peel suggests. \(Output.count(hidden, "file needs", "files need")) review. Add --all to see \(them)."+ }+/// Describes `leftover` in one line: why it matched, why it needs review when it isn't suggested (held/// back, shared with other apps, or only a possible match), and whether it needs administrator access.static func summary(of leftover: Leftover) -> String {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swiftindex f71ef4b5..0200f381 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] inlet leftovers = LeftoversCommand.Report(- app: notes, appSize: nil, leftovers: [cache], unreadableLocations: [], appStays: stays+ app: notes, appSize: nil, leftovers: [cache], needsReview: 0, unreadableLocations: [], appStays: stays)let json = try Output.jsonText(leftovers)return try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])@@ -535,17 +535,26 @@ struct CommandLineTests {#expect(Output.path(URL(filePath: "/private/other/gone")) == "/private/other/gone")}+ @Test func saysWhatIsHiddenWhenNothingIsSuggested() {+ #expect(LeftoversCommand.whenNothingIsShown(hidden: 0) == "No leftovers found.")+ #expect(LeftoversCommand.whenNothingIsShown(hidden: 1)+ == "No leftovers Peel suggests. 1 file needs review. Add --all to see it.")+ #expect(LeftoversCommand.whenNothingIsShown(hidden: 11)+ == "No leftovers Peel suggests. 11 files need review. Add --all to see them.")+ }+@Test func theLeftoversReportSaysWhereItCouldNotLook() throws {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 report = LeftoversCommand.Report(- app: app, appSize: nil, leftovers: [], unreadableLocations: [unread], appStays: nil+ app: app, appSize: nil, leftovers: [], needsReview: 3, unreadableLocations: [unread], 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["appSize"] is NSNull)}