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
Developer never lists a folder inside another it already lists
Țugui Dragoș04f74e0f0196
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swiftindex 72b2f68b..f10d6c29 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift@@ -785,10 +785,9 @@ public enum DeveloperCaches {await withTaskGroup(of: DeveloperEnvironment?.self) { group infor definition in definitions {_ = group.addTaskUnlessCancelled {- var locations: [DeveloperEnvironment.Location] = []+ var found: [(url: URL, folder: Folder)] = []for folder in definition.folders {for url in PathPattern.expand(folder.path, home: homeDirectory) {- guard !Task.isCancelled else { return nil }guard !exclusions.excludes(url), !exclusions.holds(url) else { continue }// Skips a folder that holds work kept nowhere else, such as the state Deno's// scripts keep in `location_data`. Removing it would lose that work.@@ -796,18 +795,28 @@ public enum DeveloperCaches {// Skips a symbolic link, which is how people move a big cache to another disk.// Moving the link frees nothing.guard (try? url.resourceValues(forKeys: [.isSymbolicLinkKey]).isSymbolicLink) != true else { continue }- // Awaited, never blocked on: every tool in the table is measured at once, and a- // blocked wait would hold one of the few threads that every scan in the app shares.- let contents = await measure(url)- locations.append(DeveloperEnvironment.Location(- url: url,- kind: folder.kind(at: url),- size: contents.flatMap { $0.couldNotBeRead ? nil : $0.size },- source: folder.source,- couldNotBeRead: contents?.couldNotBeRead == true- ))+ found.append((url, folder))}}+ // A pattern can reach inside a folder another pattern lists, as `*/GPUCache` reaches+ // `GPUPersistentCache/GPUCache`, and that folder goes with the one around it.+ let paths = found.map { PathPattern.comparablePath(of: $0.url) }+ var locations: [DeveloperEnvironment.Location] = []+ for (url, folder) in found {+ guard !Task.isCancelled else { return nil }+ let path = PathPattern.comparablePath(of: url)+ guard !paths.contains(where: { PathComponents.isPath(path, inside: $0) }) else { continue }+ // Awaited, never blocked on: every tool in the table is measured at once, and a+ // blocked wait would hold one of the few threads that every scan in the app shares.+ let contents = await measure(url)+ locations.append(DeveloperEnvironment.Location(+ url: url,+ kind: folder.kind(at: url),+ size: contents.flatMap { $0.couldNotBeRead ? nil : $0.size },+ source: folder.source,+ couldNotBeRead: contents?.couldNotBeRead == true+ ))+ }guard !locations.isEmpty else { return nil }return DeveloperEnvironment(id: definition.id,diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swiftindex a772705b..8500facb 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift@@ -123,6 +123,21 @@ struct DeveloperCachesTests {#expect(Set(listed) == Set(caches))}+ @Test func neverListsAFolderInsideAnotherItAlreadyLists() async throws {+ let directory = try TemporaryDirectory()+ let chrome = "Library/Application Support/Google/Chrome"+ try directory.file("\(chrome)/GPUPersistentCache/GPUCache/data_0", bytes: 4_096)+ try directory.file("\(chrome)/Default/GPUCache/data_0", bytes: 4_096)++ let environments = await DeveloperCaches.scan(homeDirectory: directory.url)++ let folder = directory.url.appending(path: chrome).path(percentEncoded: false) + "/"+ let listed = try #require(environments.first { $0.id == "chrome" }).locations.map {+ $0.url.path(percentEncoded: false).replacingOccurrences(of: folder, with: "")+ }+ #expect(Set(listed) == ["GPUPersistentCache", "Default/GPUCache"])+ }+@Test func listsABrowsersModelsWithoutSelectingThem() async throws {let directory = try TemporaryDirectory()let chrome = "Library/Application Support/Google/Chrome"