Free, open-source macOS cleaner. CleanMyMac alternative with zero telemetry. Native SwiftUI, scheduled auto-cleaning, Xcode/Homebrew/system cache cleanup. MIT licensed.
Swift cache-cleanercleanmymaccleanupdisk-cleanerdisk-spacehomebrewmac-utilitymacosmacos-appmacos-cleanermacosxnativeossosxprivacyswiftswiftuisystem-cleanerxcode-cleaner
fix(xcode): keep the cloud provider denylist aligned with canonical homes
momenbasel5b055ea168a8
diff --git a/PureMac/Logic/Utilities/ProviderPaths.swift b/PureMac/Logic/Utilities/ProviderPaths.swiftindex 10b1073..f0421dc 100644--- a/PureMac/Logic/Utilities/ProviderPaths.swift+++ b/PureMac/Logic/Utilities/ProviderPaths.swift@@ -18,25 +18,39 @@ enum ProviderPaths {/// Roots that must never be scanned, offered, or deleted. Any path equal to/// or beneath one of these is off limits.- static var deniedRoots: [String] {- let home = FileManager.default.homeDirectoryForCurrentUser.path- return [- // iCloud Drive user-visible root and its per-app containers.- "\(home)/Library/Mobile Documents",- // Third-party providers (Dropbox, OneDrive, Google Drive, ...).- "\(home)/Library/CloudStorage",- // FileProvider framework state and per-provider domains.- "\(home)/Library/Application Support/FileProvider",- "\(home)/Library/Application Support/CloudDocs",- // Provider extension containers.- "\(home)/Library/Daemon Containers",- // Live databases, not reclaimable caches, despite living in Caches.- "\(home)/Library/Caches/CloudKit",- "\(home)/Library/Caches/com.apple.bird",- "\(home)/Library/Caches/com.apple.cloudkit",- "\(home)/Library/Caches/com.apple.cloudd",- "\(home)/Library/Caches/com.apple.FileProvider",- ]+ ///+ /// The engines canonicalize a symlinked home, so the roots are spelled+ /// under every form of the home: literal, symlink-resolved, and resolved+ /// then standardized. Otherwise a canonical path under a symlinked home+ /// would never match a root built from the literal home.+ static func deniedRoots(+ homeDirectory: URL = FileManager.default.homeDirectoryForCurrentUser+ ) -> [String] {+ let resolved = homeDirectory.resolvingSymlinksInPath()+ var homes: [String] = []+ for home in [homeDirectory.standardizedFileURL.path, resolved.path, resolved.standardizedFileURL.path]+ where !homes.contains(home) {+ homes.append(home)+ }+ return homes.flatMap { home in+ [+ // iCloud Drive user-visible root and its per-app containers.+ "\(home)/Library/Mobile Documents",+ // Third-party providers (Dropbox, OneDrive, Google Drive, ...).+ "\(home)/Library/CloudStorage",+ // FileProvider framework state and per-provider domains.+ "\(home)/Library/Application Support/FileProvider",+ "\(home)/Library/Application Support/CloudDocs",+ // Provider extension containers.+ "\(home)/Library/Daemon Containers",+ // Live databases, not reclaimable caches, despite living in Caches.+ "\(home)/Library/Caches/CloudKit",+ "\(home)/Library/Caches/com.apple.bird",+ "\(home)/Library/Caches/com.apple.cloudkit",+ "\(home)/Library/Caches/com.apple.cloudd",+ "\(home)/Library/Caches/com.apple.FileProvider",+ ]+ }}/// True when `path` is inside provider-owned state and must be left alone.@@ -46,7 +60,11 @@ enum ProviderPaths {/// enabled, `~/Desktop` and `~/Documents` resolve into/// `~/Library/Mobile Documents/com~apple~CloudDocs`, so an innocuous-looking/// root can walk straight into iCloud state.- static func isProviderOwned(_ path: String) -> Bool {+ static func isProviderOwned(+ _ path: String,+ homeDirectory: URL = FileManager.default.homeDirectoryForCurrentUser+ ) -> Bool {+ let roots = deniedRoots(homeDirectory: homeDirectory)let candidates = [(path as NSString).standardizingPath,URL(fileURLWithPath: path).resolvingSymlinksInPath().path,@@ -55,7 +73,7 @@ enum ProviderPaths {// Any component of the form `com~apple~CloudDocs` (or any other// provider domain) marks provider territory regardless of location.if candidate.contains("com~apple~") { return true }- for root in deniedRoots where candidate == root || candidate.hasPrefix(root + "/") {+ for root in roots where candidate == root || candidate.hasPrefix(root + "/") {return true}}diff --git a/PureMac/Services/CleaningEngine.swift b/PureMac/Services/CleaningEngine.swiftindex bdf3e9c..5a4dbe1 100644--- a/PureMac/Services/CleaningEngine.swift+++ b/PureMac/Services/CleaningEngine.swift@@ -605,7 +605,7 @@ actor CleaningEngine {// Checked before the allowlist because several provider directories live// inside ~/Library/Caches and ~/Library/Application Support, which are// themselves allowed roots.- if ProviderPaths.isProviderOwned(resolvedPath) {+ if ProviderPaths.isProviderOwned(resolvedPath, homeDirectory: homeDirectory) {Logger.shared.log("Refusing to delete cloud provider state: \(resolvedPath)",level: .warning@@ -864,7 +864,7 @@ actor CleaningEngine {/// was explicitly surfaced by a scanner (e.g. scanLargeFiles). Whole-subtree/// deletion of those roots remains blocked.func isExplicitSingleFileDeletable(resolvedPath: String) -> Bool {- let home = fileManager.homeDirectoryForCurrentUser.path+ let home = homeDirectory.pathlet perFileRoots = ["\(home)/Downloads/","\(home)/Documents/",diff --git a/PureMac/Services/ScanEngine.swift b/PureMac/Services/ScanEngine.swiftindex d70133b..67e47b9 100644--- a/PureMac/Services/ScanEngine.swift+++ b/PureMac/Services/ScanEngine.swift@@ -152,7 +152,7 @@ actor ScanEngine {"\(home)/Library/Caches/npm","\(home)/Library/Caches/Yarn","\(home)/Library/Caches/dev.kdrag0n.MacVirt",- ] + ProviderPaths.deniedRoots).map(normalizePath))+ ] + ProviderPaths.deniedRoots(homeDirectory: URL(fileURLWithPath: home, isDirectory: true))).map(normalizePath))// Dynamically enumerate ~/Library/Caches/ so every subdirectory is visiblelet cachePath = "\(home)/Library/Caches"diff --git a/PureMacTests/XcodeBuildMCPDerivedDataSupportTests.swift b/PureMacTests/XcodeBuildMCPDerivedDataSupportTests.swiftindex 2988a84..00ae888 100644--- a/PureMacTests/XcodeBuildMCPDerivedDataSupportTests.swift+++ b/PureMacTests/XcodeBuildMCPDerivedDataSupportTests.swift@@ -540,6 +540,52 @@ final class XcodeBuildMCPDerivedDataSupportTests: XCTestCase {XCTAssertFalse(fileManager.fileExists(atPath: cacheDir.appendingPathComponent("blob").path))}+ func testSymlinkedHomeStillRefusesCloudProviderState() async throws {+ let fileManager = FileManager.default+ let container = fileManager.temporaryDirectory+ .appendingPathComponent("PureMac-XcodeBuildMCP-ProviderHome-\(UUID().uuidString)", isDirectory: true)+ defer { try? fileManager.removeItem(at: container) }++ let realHome = container.appendingPathComponent("real-home", isDirectory: true)+ let linkedHome = container.appendingPathComponent("linked-home", isDirectory: true)+ let birdCache = realHome.appendingPathComponent("Library/Caches/com.apple.bird", isDirectory: true)+ let cloudStorage = realHome.appendingPathComponent("Library/CloudStorage/Dropbox", isDirectory: true)+ let ordinaryCache = realHome.appendingPathComponent("Library/Caches/com.example.junk", isDirectory: true)+ for directory in [birdCache, cloudStorage, ordinaryCache] {+ try fileManager.createDirectory(at: directory, withIntermediateDirectories: true)+ try Data(repeating: 0x22, count: 4_096).write(to: directory.appendingPathComponent("blob"))+ }+ try fileManager.createSymbolicLink(at: linkedHome, withDestinationURL: realHome)++ let scan = await ScanEngine(homeDirectory: linkedHome).scanCategory(.userCache)+ XCTAssertTrue(scan.items.contains { $0.path.hasSuffix("/Library/Caches/com.example.junk") })+ XCTAssertFalse(scan.items.contains { $0.path.hasSuffix("/Library/Caches/com.apple.bird") })++ let items = [birdCache, cloudStorage].map { directory in+ CleanableItem(+ name: directory.lastPathComponent,+ path: directory.path,+ size: 4_096,+ category: .userCache,+ isSelected: true,+ lastModified: nil+ )+ }+ let result = await CleaningEngine(homeDirectory: linkedHome).cleanItems(items) { _ in }++ XCTAssertEqual(result.itemsCleaned, 0)+ XCTAssertTrue(result.cleanedPaths.isEmpty)+ XCTAssertEqual(result.errors.count, 2)+ for directory in [birdCache, cloudStorage] {+ XCTAssertTrue(fileManager.fileExists(atPath: directory.appendingPathComponent("blob").path))+ }+ XCTAssertTrue(ProviderPaths.isProviderOwned(birdCache.path, homeDirectory: linkedHome))+ XCTAssertTrue(ProviderPaths.isProviderOwned(+ linkedHome.appendingPathComponent("Library/CloudStorage/Dropbox").path,+ homeDirectory: linkedHome+ ))+ }+func testScheduledAutoCleanAllowsOldUnlockedManagedDerivedData() {let item = CleanableItem(name: "XcodeBuildMCP: PureMac",