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
peel duplicates says which chosen folders it didn't look in
Țugui Dragoș2adc3d2b36fb
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swiftindex b42d8df9..aa80d1e6 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift@@ -414,22 +414,25 @@ struct DuplicatesCommand: AsyncParsableCommand {@OptionGroup var output: OutputOptions- private struct Record: Encodable {+ struct Record: Encodable {let size: Int64let reclaimableSize: Int64let files: [String]}- private struct FolderRecord: Encodable {+ struct FolderRecord: Encodable {let size: Int64let reclaimableSize: Int64let fileCount: Intlet folders: [String]}- private struct Found: Encodable {+ struct Found: Encodable {let folders: [FolderRecord]let files: [Record]+ /// Folders macOS kept Peel out of, and chosen folders it didn't look in: there may be duplicates there.+ let unreadableLocations: [String]+ let skippedLocations: [String]}/// Checks the folders here rather than in `run()`: only while it parses does ArgumentParser know which@@ -457,24 +460,12 @@ struct DuplicatesCommand: AsyncParsableCommand {options.minimumSize = minimumSize?.bytes ?? 1let scan = try await finder.scan(options)if removal.remove {- if !scan.unreadableLocations.isEmpty {- Output.note(Output.fullDiskAccessNote)- }+ Self.notes(for: scan).forEach(Output.note)return try await clean(scan, using: TrashService(exclusions: await ExclusionStore().load()))}if output.json {- try Output.json(Found(- folders: scan.folderGroups.map { group in- FolderRecord(- size: group.size,- reclaimableSize: group.reclaimableSize,- fileCount: group.fileCount,- folders: group.folders.map { Output.path($0.url) }- )- },- files: scan.groups.map { Record(size: $0.size, reclaimableSize: $0.reclaimableSize, files: $0.files.map { Output.path($0.url) }) }- ))+ try Output.json(Self.found(in: scan))} else if scan.groups.isEmpty, scan.folderGroups.isEmpty {Output.line("No duplicates found.")} else {@@ -489,9 +480,37 @@ struct DuplicatesCommand: AsyncParsableCommand {let total = scan.groups.reduce(0) { $0 + $1.reclaimableSize } + scan.folderGroups.reduce(0) { $0 + $1.reclaimableSize }Output.line("Total to free: \(Output.size(total))")}+ Self.notes(for: scan).forEach(Output.note)+ }++ /// What the scan didn't look at, said on standard error whatever the output, so that "No duplicates found."+ /// or an empty list is not read as a folder without any.+ static func notes(for scan: DuplicateScan) -> [String] {+ var notes: [String] = []if !scan.unreadableLocations.isEmpty {- Output.note(Output.fullDiskAccessNote)+ notes.append(Output.fullDiskAccessNote)}+ if !scan.skippedLocations.isEmpty {+ let folders = scan.skippedLocations.map(Output.path).joined(separator: ", ")+ notes.append("Peel didn't look in \(folders), so there may be duplicates there. It leaves repositories alone, and doesn't scan iCloud Drive, app data, or system folders.")+ }+ return notes+ }++ static func found(in scan: DuplicateScan) -> Found {+ Found(+ folders: scan.folderGroups.map { group in+ FolderRecord(+ size: group.size,+ reclaimableSize: group.reclaimableSize,+ fileCount: group.fileCount,+ folders: group.folders.map { Output.path($0.url) }+ )+ },+ files: scan.groups.map { Record(size: $0.size, reclaimableSize: $0.reclaimableSize, files: $0.files.map { Output.path($0.url) }) },+ unreadableLocations: scan.unreadableLocations.map(Output.path),+ skippedLocations: scan.skippedLocations.map(Output.path)+ )}static func heading(for group: DuplicateFolderGroup) -> String {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swiftindex 71a8abb2..21ccd2df 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift@@ -395,6 +395,32 @@ struct FileCommandTests {#expect(report["unreadableLocations"] as? [String] == ["/Users/me/Library/Containers"])}+ /// A chosen folder Peel didn't look in, such as a repository, is said, so "No duplicates found." is not read+ /// as a folder without any.+ @Test func saysWhichFoldersItDidNotLookIn() {+ let skipped = URL(filePath: "/Users/me/Projects/app", directoryHint: .isDirectory)+ let scan = DuplicateScan(groups: [], unreadableLocations: [], skippedLocations: [skipped])++ let notes = DuplicatesCommand.notes(for: scan)++ #expect(notes.contains { $0.hasPrefix("Peel didn't look in /Users/me/Projects/app, so there may be duplicates there.") })+ }++ /// `peel duplicates --json` names the folders it couldn't read and the chosen folders it didn't look in.+ @Test func theDuplicatesReportSaysWhereItCouldNotLook() throws {+ let scan = DuplicateScan(+ groups: [],+ unreadableLocations: [URL(filePath: "/Users/me/Locked", directoryHint: .isDirectory)],+ skippedLocations: [URL(filePath: "/Users/me/Projects/app", directoryHint: .isDirectory)]+ )++ let json = try Output.jsonText(DuplicatesCommand.found(in: scan))++ let found = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])+ #expect(found["unreadableLocations"] as? [String] == ["/Users/me/Locked"])+ #expect(found["skippedLocations"] as? [String] == ["/Users/me/Projects/app"])+ }+/// `peel caches --json` says which folders `--remove` would take.@Test func theCachesListSaysWhatRemoveWouldTake() throws {let directory = try TemporaryDirectory()