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
Count in peel orphans what --remove moves, and say where its scan stopped short
Țugui Dragoș86c5bc6eea56
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swiftindex ab0cb651..9009fddd 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift@@ -24,6 +24,9 @@ struct OrphansCommand: AsyncParsableCommand {let groups: [Group]let forAnAdministrator: [ForAnAdministrator]let unreadableLocations: [String]+ /// The places with more folders inside than Peel looks into, where an orphaned file may be that isn't listed.+ let cutShortLocations: [String]+ let needsFullDiskAccess: Boolstruct ForAnAdministrator: Encodable {let path: String@@ -56,6 +59,8 @@ struct OrphansCommand: AsyncParsableCommand {struct Group: Encodable {let identifier: Stringlet size: MeasuredSize+ /// What `--remove` would move of the group: its size without the files Peel holds back.+ let movable: MeasuredSizelet confidence: Stringlet why: Stringlet files: [File]@@ -176,6 +181,7 @@ struct OrphansCommand: AsyncParsableCommand {Report.Group(identifier: group.identifier,size: MeasuredSize(group.total),+ movable: MeasuredSize(SizeTotal(moving(group).map(\.size))),confidence: group.confidence.levelName,why: group.confidence.summary,files: group.items.map { item in@@ -193,7 +199,9 @@ struct OrphansCommand: AsyncParsableCommand {confidence: entry.claim?.confidence.summary)},- unreadableLocations: scan.unreadableLocations.map { Output.path($0.url) }+ unreadableLocations: scan.unreadableLocations.map { Output.path($0.url) },+ cutShortLocations: scan.cutShortLocations.map { Output.path($0.url) },+ needsFullDiskAccess: scan.needsFullDiskAccess)}@@ -217,8 +225,14 @@ struct OrphansCommand: AsyncParsableCommand {}}+ /// What `--remove` moves of `group`: every file but those Peel holds back, which the list says stay.+ static func moving(_ group: OrphanGroup) -> [OrphanItem] {+ group.items.filter { $0.heldBack == nil }+ }+static func heading(for group: OrphanGroup) -> String {- "\(group.identifier) \(Output.size(group.total)) \(group.confidence.levelName): \(group.confidence.summary)"+ let moving = Output.size(SizeTotal(moving(group).map(\.size)))+ return "\(group.identifier) \(moving) \(group.confidence.levelName): \(group.confidence.summary)"}static func rows(for group: OrphanGroup) -> [[String]] {@@ -241,7 +255,7 @@ struct OrphansCommand: AsyncParsableCommand {guard let group = wanted.first else {throw CommandFailure("Nothing orphaned is called \(Output.quoted(identifier)). See `peel orphans`.")}- let items = group.items.filter { $0.heldBack == nil }+ let items = Self.moving(group)// Nobody asked for a held back file on its own, so it is said here and never recorded as refused.let staying = group.items.compactMap { item in item.heldBack.map { "\(Output.plain(Output.path(item.url))) stays: \($0.summary)" } }guard !items.isEmpty else {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swiftindex 3744c16f..19f6fd34 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift@@ -562,6 +562,7 @@ struct FileCommandTests {["10 bytes", Output.path(group.items[1].url), "stays: holds a wallet or a signing key"],["10 bytes", Output.path(group.items[2].url), "stays: holds a photo, music, or video library"],])+ #expect(OrphansCommand.heading(for: group).hasPrefix("com.example.gone 10 bytes "), "the files that stay counted")}/// `peel orphans --json` says why `--remove` leaves each file it leaves, and which folders macOS kept Peel out of.@@ -573,15 +574,20 @@ struct FileCommandTests {])let unread = SearchLocation(kind: .containers, url: URL(filePath: "/Users/me/Library/Containers", directoryHint: .isDirectory))- let json = try Output.jsonText(- OrphansCommand.report(for: OrphanScan(groups: [group], unreadableLocations: [unread]))- )+ var scan = OrphanScan(groups: [group], unreadableLocations: [unread], needsFullDiskAccess: true)+ scan.cutShortLocations = [unread]+ let json = try Output.jsonText(OrphansCommand.report(for: scan))let report = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])- let files = try #require((report["groups"] as? [[String: Any]])?.first?["files"] as? [[String: Any]])+ let listed = try #require((report["groups"] as? [[String: Any]])?.first)+ let files = try #require(listed["files"] as? [[String: Any]])#expect(files[0]["heldBack"] is NSNull)#expect(files[1]["heldBack"] as? String == "holdsAWallet")+ #expect(listed["size"] as? Int == 20)+ #expect(listed["movable"] as? Int == 10, "what --remove would move")#expect(report["unreadableLocations"] as? [String] == ["/Users/me/Library/Containers"])+ #expect(report["cutShortLocations"] as? [String] == ["/Users/me/Library/Containers"])+ #expect(report["needsFullDiskAccess"] as? Bool == true)}@Test func listsApartWhatOnlyAnAdministratorCanMove() throws {