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
Name the folders Build Artifacts could not read
Țugui Dragoș5dcd43a04908
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swiftindex bf583c1a..83b1c61c 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift@@ -445,7 +445,9 @@ struct ProjectsCommand: AsyncParsableCommand {static func notes(for scan: ProjectArtifacts.Scan) -> [String] {var notes: [String] = []if !scan.unreadableLocations.isEmpty {- notes.append(Output.fullDiskAccessNote)+ notes.append(+ Output.unreadableNote(for: scan.unreadableLocations, needsFullDiskAccess: scan.needsFullDiskAccess)+ )}if scan.wasCutShort {notes.append("There were more folders than Peel looks at in one go, so this list isn't all of them.")diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swiftindex 35017d82..aa0afffd 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift@@ -427,9 +427,10 @@ public enum ProjectArtifacts {public var artifacts: [ProjectArtifact] = []/// True when the scan reached `maximumFolders` and left the deepest folders unread.public var wasCutShort = false+ /// The folders that are there and could not be read, or did not answer in time, so what they hold isn't known.public var unreadableLocations: [URL] = []-- public var needsFullDiskAccess: Bool { !unreadableLocations.isEmpty }+ /// True when macOS kept Peel out of one of them for want of Full Disk Access.+ public var needsFullDiskAccess = false}@concurrent@@ -439,15 +440,17 @@ public enum ProjectArtifacts {@concurrentstatic func scan(roots: [URL], exclusions: Exclusions, measure: @escaping LeftoverScanner.Measure) async -> Scan {- await withTaskGroup(of: (artifacts: [ProjectArtifact], wasCutShort: Bool).self) { group in+ await withTaskGroup(of: (artifacts: [ProjectArtifact], wasCutShort: Bool, unreadable: [URL]).self) { group infor root in roots where isSearchable(root) {group.addTask { await artifacts(in: root, exclusions: exclusions, measure: measure) }}var found: [ProjectArtifact] = []var seen: Set<URL> = []var wasCutShort = false+ var unreadable: [URL] = []for await result in group {wasCutShort = wasCutShort || result.wasCutShort+ unreadable += result.unreadablefor artifact in result.artifacts where seen.insert(artifact.url).inserted {found.append(artifact)}@@ -455,7 +458,10 @@ public enum ProjectArtifacts {return Scan(artifacts: found.sorted { SizeTotal([$0.size]) > SizeTotal([$1.size]) },wasCutShort: wasCutShort,- unreadableLocations: roots.filter { isSearchable($0) && FullDiskAccess.canList($0) == .missing }+ unreadableLocations: unreadable.sorted {+ PathPattern.comparablePath(of: $0) < PathPattern.comparablePath(of: $1)+ },+ needsFullDiskAccess: unreadable.contains { FullDiskAccess.canList($0) == .missing })}}@@ -524,8 +530,9 @@ public enum ProjectArtifacts {exclusions: Exclusions,measure: LeftoverScanner.Measure,listing: @escaping @Sendable (URL) -> [URL]? = contents(of:)- ) async -> (artifacts: [ProjectArtifact], wasCutShort: Bool) {+ ) async -> (artifacts: [ProjectArtifact], wasCutShort: Bool, unreadable: [URL]) {var found: [ProjectArtifact] = []+ var unreadable: [URL] = []var queue: [(url: URL, depth: Int)] = [(root, 0)]// An index, since `removeFirst` would make the walk quadratic.var next = 0@@ -544,7 +551,11 @@ public enum ProjectArtifacts {let answer = await SlowRead.answer(within: FileSize.budget) { _ inlook(in: folder, exclusions: exclusions, listing: listing)}- guard let look = answer ?? nil else { continue }+ // A folder that went away during the walk held nothing; one still there and not read is not known.+ guard let look = answer ?? nil else {+ if !folder.isMissing { unreadable.append(folder) }+ continue+ }ScanCount.current?.add(look.entries.count)let artifactNames = Set(look.found.map(\.name))for artifact in look.found {@@ -584,7 +595,7 @@ public enum ProjectArtifacts {queue.append((entry, depth + 1))}}- return (found, next < queue.count)+ return (found, next < queue.count, unreadable)}/// What one folder holds and which of its entries are artifacts.diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swiftindex 39e90e14..5a1ee94f 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift@@ -576,12 +576,19 @@ struct FileCommandTests {/// A chosen folder macOS kept Peel out of is said whatever the output, so an empty answer is not read as none.@Test func saysWhenItCouldNotLookInAChosenFolder() throws {let locked = URL(filePath: "/Users/me/Library/Safari", directoryHint: .isDirectory)- let scan = ProjectArtifacts.Scan(artifacts: [], wasCutShort: true, unreadableLocations: [locked])+ let scan = ProjectArtifacts.Scan(+ artifacts: [], wasCutShort: true, unreadableLocations: [locked], needsFullDiskAccess: true+ )#expect(ProjectsCommand.notes(for: scan) == [Output.fullDiskAccessNote,"There were more folders than Peel looks at in one go, so this list isn't all of them.",])+ let app = URL(filePath: "/Users/me/Code/app", directoryHint: .isDirectory)+ let closed = ProjectArtifacts.Scan(unreadableLocations: [app])+ #expect(ProjectsCommand.notes(for: closed) == [+ "Peel couldn't look inside /Users/me/Code/app, so something may be there that isn't listed.",+ ])let json = try Output.jsonText(ProjectsCommand.report(for: scan))let report = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])#expect(report["unreadableLocations"] as? [String] == ["/Users/me/Library/Safari"])diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swiftindex d713821a..04ad4c31 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift@@ -109,14 +109,28 @@ struct ProjectArtifactsTests {#expect(ProjectArtifacts.lastChange(of: [artifact("build", changed: nil, certain: true)]) == .none)}- @Test(.permissionsHold) func doesNotBlameFullDiskAccessForOrdinaryPermissions() async throws {+ /// A folder ordinary permissions close is named as not read, never taken for one with nothing built in it, and+ /// Full Disk Access, which would not open it either, is not blamed.+ @Test(.permissionsHold) func saysWhichFoldersItCouldNotReadWithoutBlamingFullDiskAccess() async throws {let directory = try TemporaryDirectory()try directory.file("Code/app/package.json", bytes: 16)+ try directory.file("Work/open/package.json", bytes: 16)+ try directory.file("Work/closed/package.json", bytes: 16)try directory.setPermissions(0, of: "Code")- defer { try? directory.setPermissions(0o755, of: "Code") }+ try directory.setPermissions(0, of: "Work/closed")+ defer {+ try? directory.setPermissions(0o755, of: "Code")+ try? directory.setPermissions(0o755, of: "Work/closed")+ }+ let code = directory.url.appending(path: "Code", directoryHint: .isDirectory)+ let work = directory.url.appending(path: "Work", directoryHint: .isDirectory)++ let scan = await ProjectArtifacts.scan(roots: [code, work])- let scan = await ProjectArtifacts.scan(roots: [directory.url.appending(path: "Code", directoryHint: .isDirectory)])#expect(scan.artifacts.isEmpty)+ #expect(scan.unreadableLocations.map(PathPattern.comparablePath) == [+ PathPattern.comparablePath(of: code), PathPattern.comparablePath(of: work.appending(path: "closed")),+ ])#expect(!scan.needsFullDiskAccess)}diff --git a/Peel/Model/ProjectLibrary.swift b/Peel/Model/ProjectLibrary.swiftindex a5de1914..be8a7436 100644--- a/Peel/Model/ProjectLibrary.swift+++ b/Peel/Model/ProjectLibrary.swift@@ -34,6 +34,8 @@ final class ProjectLibrary {/// True when the scan reached its limit on how many folders it reads, so the list may be incomplete.private(set) var wasCutShort = falseprivate(set) var needsFullDiskAccess = false+ /// The folders the last scan could not read, so what they hold isn't known.+ private(set) var unreadable: [URL] = []/// Folders the last Add refused, with the reason, until the next one.private(set) var refused: [(url: URL, reason: ProjectArtifacts.Refusal)] = []var selection: URL?@@ -60,6 +62,7 @@ final class ProjectLibrary {let artifacts = scan.artifactswasCutShort = scan.wasCutShortneedsFullDiskAccess = scan.needsFullDiskAccess+ unreadable = scan.unreadableLocationslet result = Dictionary(grouping: artifacts, by: \.project).map {ProjectGroup(diff --git a/Peel/Views/Projects/ProjectList.swift b/Peel/Views/Projects/ProjectList.swiftindex 79b3ae54..7486ada1 100644--- a/Peel/Views/Projects/ProjectList.swift+++ b/Peel/Views/Projects/ProjectList.swift@@ -30,6 +30,8 @@ struct ProjectList: View {List(selection: $projects.selection) {if projects.needsFullDiskAccess, !filtered.isEmpty {FullDiskAccessBanner()+ } else if !projects.unreadable.isEmpty, !filtered.isEmpty {+ UnreadableFoldersNotice(folders: projects.unreadable)}ForEach(filtered) { group inProjectRow(group: group)@@ -63,6 +65,12 @@ struct ProjectList: View {} actions: {Button("Open System Settings") { home.openFullDiskAccessSettings() }}+ } else if projects.groups?.isEmpty == true, !projects.unreadable.isEmpty {+ ContentUnavailableView {+ Label("Not Everything Could Be Read", systemImage: "exclamationmark.triangle")+ } description: {+ Text("Peel couldn’t look inside \(projects.unreadable.map(\.abbreviatedPath).formatted(.list(type: .and))), so something may be there that isn’t listed here.")+ }} else if projects.groups?.isEmpty == true {ContentUnavailableView("Nothing Built Here",@@ -95,7 +103,7 @@ struct ProjectList: View {projects.isScanning,found: projects.summary,couldNotLook: projects.folders.isEmpty ? "No Folders Yet"- : projects.needsFullDiskAccess ? "Not Everything Could Be Read" : nil,+ : !projects.unreadable.isEmpty ? "Not Everything Could Be Read" : nil,wasStopped: projects.scanRun.wasStopped).toolbar {