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
Never look into a folder that lives only in the cloud
Țugui Dragoșda45125fdc2d
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swiftindex c2ae070f..83599b97 100644--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift@@ -13,6 +13,7 @@ public struct DuplicateFinder: Sendable {private let homeDirectory: URLprivate let exclusions: Exclusionsprivate let digestMemory: DigestMemory?+ private let isDataless: @Sendable (URL) -> Bool/// Without a `digestMemory`, every file is read and no digest is saved, so tests never touch the user's/// saved digests.@@ -20,10 +21,23 @@ public struct DuplicateFinder: Sendable {homeDirectory: URL = .homeDirectory,exclusions: Exclusions = .none,digestMemory: DigestMemory? = nil+ ) {+ self.init(homeDirectory: homeDirectory, exclusions: exclusions, digestMemory: digestMemory) {+ FileSize.isDataless($0)+ }+ }++ /// `isDataless` stands in for a folder a file provider keeps only in the cloud, which no test can make.+ init(+ homeDirectory: URL,+ exclusions: Exclusions,+ digestMemory: DigestMemory?,+ isDataless: @escaping @Sendable (URL) -> Bool) {self.exclusions = exclusionsself.homeDirectory = homeDirectory.resolvingSymlinksInPath()self.digestMemory = digestMemory+ self.isDataless = isDataless}public var defaultFolders: [URL] {@@ -78,7 +92,8 @@ public struct DuplicateFinder: Sendable {? try await FolderDuplicates(managed: Self.managedPaths(home: homeDirectory),exclusions: exclusions,- neverProjects: neverProjects+ neverProjects: neverProjects,+ isDataless: isDataless).groups(in: scannable,minimumSize: options.minimumSize,@@ -210,7 +225,8 @@ public struct DuplicateFinder: Sendable {// already offered whole covers everything inside it, so its files are not offered again.if url.lastPathComponent == "node_modules" || excludedFolders.contains(Self.path(of: url))|| spokenFor.contains(Self.path(of: url))- || exclusions.excludes(url) || Self.isRepository(url) || Self.isAUserLibrary(url) {+ || exclusions.excludes(url) || Self.isRepository(url) || Self.isAUserLibrary(url)+ || isDataless(url) {enumerator.skipDescendants()}returndiff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swiftindex 1ffed652..9267c5b3 100644--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift@@ -12,11 +12,18 @@ struct FolderDuplicates: Sendable {private let exclusions: Exclusionsprivate let managed: Set<String>private let neverProjects: Set<String>-- init(managed: Set<String> = [], exclusions: Exclusions = .none, neverProjects: Set<String> = []) {+ private let isDataless: @Sendable (URL) -> Bool++ init(+ managed: Set<String> = [],+ exclusions: Exclusions = .none,+ neverProjects: Set<String> = [],+ isDataless: @escaping @Sendable (URL) -> Bool = { FileSize.isDataless($0) }+ ) {self.managed = managedself.exclusions = exclusionsself.neverProjects = neverProjects+ self.isDataless = isDataless}private final class Folder {@@ -211,7 +218,8 @@ struct FolderDuplicates: Sendable {guard !managed.contains(DuplicateFinder.path(of: entry)),entry.lastPathComponent != "node_modules",!DuplicateFinder.isAUserLibrary(entry),- !DuplicateFinder.isRepository(entry)+ !DuplicateFinder.isRepository(entry),+ !isDataless(entry)else { return .leftOut }return .folder(name: entry.lastPathComponent,diff --git a/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift b/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swiftindex 9776ba7f..12ae51b7 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift@@ -211,6 +211,7 @@ public enum CloudStorage {deadline: ContinuousClock.Instant,countingFor scan: ScanCount?,isSafe: (URLResourceValues) -> Bool = isSafeToFree(_:),+ isDataless: (URL) -> Bool = FileSize.isDataless(_:),unless isGivenUp: () -> Bool) {let root = home.appending(path: "Library/Mobile Documents", directoryHint: .isDirectory)@@ -243,6 +244,10 @@ public enum CloudStorage {return}scan?.add(1)+ if isDataless(url) {+ enumerator.skipDescendants()+ continue+ }guardlet values = try? url.resourceValues(forKeys: keys),values.isRegularFile == true || values.isPackage == true,diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swiftindex e83a76c0..94526bbd 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift@@ -144,6 +144,30 @@ struct CloudStorageTests {#expect(sizes["clone.bin"] == nil, "a clone frees nothing")}+ /// A folder kept only in the cloud, which no test can make, is named to the walk.+ @Test func neverLooksIntoAFolderThatLivesOnlyInTheCloud() throws {+ let directory = try TemporaryDirectory()+ let drive = "Library/Mobile Documents/com~apple~CloudDocs"+ try directory.file("\(drive)/plain.bin", bytes: 3_000_000)+ try directory.file("\(drive)/Evicted/inside.bin", bytes: 3_000_000)+ let evicted = PathPattern.comparablePath(of: directory.url.appending(path: "\(drive)/Evicted"))++ let collector = CloudStorage.Collector()+ CloudStorage.collect(+ home: directory.url,+ minimumSize: 1,+ exclusions: .none,+ into: collector,+ deadline: .now + .seconds(20),+ countingFor: nil,+ isSafe: { _ in true },+ isDataless: { PathPattern.comparablePath(of: $0) == evicted },+ unless: { false }+ )++ #expect(collector.collected.files.map(\.name) == ["plain.bin"])+ }+/// A download that takes a row's worth of space but shares it with another copy frees nothing, so it is left/// out of the list and counted, for the page to say why it is missing.@Test func countsTheDownloadsLeftOutBecauseAnotherCopySharesTheirSpace() throws {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swiftindex f8ff47b5..31ddca1a 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift@@ -106,6 +106,22 @@ struct FolderDuplicateTests {#expect(result.suggestedFolderSelection.map(\.lastPathComponent) == ["Trip"])}+ /// A folder kept only in the cloud, which no test can make, is named to the scan.+ @Test func aFolderThatLivesOnlyInTheCloudIsNeverLookedInto() async throws {+ let directory = try TemporaryDirectory()+ try trip(in: directory)+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ let evicted = PathPattern.comparablePath(of: home.appending(path: "Pictures/Trip"))+ let finder = DuplicateFinder(homeDirectory: home, exclusions: .none, digestMemory: nil) { url in+ PathPattern.comparablePath(of: url) == evicted+ }++ let result = try await finder.scan(.everySize(in: [home]))++ #expect(result.folderGroups.isEmpty)+ #expect(result.groups.isEmpty)+ }+/// The folder row speaks for every file under it, so the same bytes are never offered twice.@Test func filesInsideAnOfferedFolderAreNotListedOnTheirOwn() async throws {let directory = try TemporaryDirectory()