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
Space never selects a cache macOS keeps for its own services
Țugui Dragoș2bb995ac987e
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex a3059791..668bb1d3 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -68111,6 +68111,112 @@}}},+ "Not selected: macOS keeps this cache for its own services, which may be using it right now." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nevybráno: systém macOS si tuto mezipaměť uchovává pro své vlastní služby, které ji možná právě teď používají."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nicht ausgewählt: macOS bewahrt diesen Cache für seine eigenen Dienste auf, die ihn möglicherweise gerade verwenden."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Sin seleccionar: macOS guarda esta caché para sus propios servicios, que podrían estar usándola ahora mismo."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Non sélectionné : macOS conserve ce cache pour ses propres services, qui l’utilisent peut-être en ce moment."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Non selezionato: macOS conserva questa cache per i propri servizi, che potrebbero usarla proprio ora."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "未選択: このキャッシュはmacOSが自身のサービスのために保持しているもので、現在使用中の可能性があります。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "선택되지 않음: macOS가 자체 서비스를 위해 이 캐시를 보관하며, 해당 서비스가 지금 이 캐시를 사용하고 있을 수 있습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Niet geselecteerd: macOS bewaart deze cache voor zijn eigen diensten, die hem misschien op dit moment gebruiken."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nie zaznaczono: macOS przechowuje tę pamięć podręczną na potrzeby własnych usług, które mogą z niej właśnie korzystać."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Não selecionado: o macOS mantém este cache para os próprios serviços, que podem estar usando-o neste momento."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Neselectat: macOS păstrează această memorie tampon pentru propriile servicii, care o pot utiliza chiar acum."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Не выбрано: macOS хранит этот кэш для своих служб, которые, возможно, используют его прямо сейчас."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Inte markerad: macOS behåller den här cachen för sina egna tjänster, som kanske använder den just nu."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Seçilmedi: macOS bu önbelleği kendi hizmetleri için tutuyor; bunlar şu anda onu kullanıyor olabilir."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Не вибрано: macOS зберігає цей кеш для власних служб, які можуть саме зараз ним користуватися."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "未选择:macOS为其自身服务保留此缓存,这些服务现在可能正在使用它。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "未選取:macOS為自己的服務保留此快取,這些服務現在可能正在使用它。"+ }+ }+ }+ },"Not selected: macOS wouldn’t let Peel read inside, so what is in there isn’t known. If Peel doesn’t have Full Disk Access yet, giving it in System Settings may let it see." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swiftindex 237f4eca..989ef5e0 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift@@ -271,6 +271,7 @@ extension HoldBack {case .holdsKeys: "holds a wallet or a key Peel protects"case .insideAnotherAppsFolder: "inside another app's folder"case .beyondTheHelper: "needs an administrator, and Peel's helper may not move it"+ case .keptByMacOS: "a cache macOS keeps for itself"}}}diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swiftindex 3c12bf8f..7756849c 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift@@ -59,6 +59,8 @@ public enum HoldBack: String, Sendable, Hashable {case insideAnotherAppsFolder/// Needs an administrator, and the helper's own rule refuses it (`HelperReach`).case beyondTheHelper+ /// A cache macOS keeps for its own services, which may be using it at any moment (`SystemCaches`).+ case keptByMacOS/// True when the item cannot be selected at all, rather than only left unselected.public var cannotBeMoved: Bool {diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swiftindex 2c8f2647..8a5fd7d6 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift@@ -51,12 +51,16 @@ public enum SpaceRemoval {measure: LeftoverScanner.Measure) async -> Plan {let children = children(of: item, environment: environment, exclusions: exclusions, running: running)+ let caches = environment.locations.filter { $0.kind == .caches }+ let cachesFolders = Set(caches.map { PathPattern.comparablePath(of: $0.url) })var sizes: [URL: Int64] = [:]var heldBack: [URL: HoldBack] = [:]for child in children.removable where !Task.isCancelled {let contents = await measure(child)sizes[child] = contents.flatMap { $0.couldNotBeRead ? nil : $0.size }- heldBack[child] = HoldBack.seen(in: contents)+ let isMacOSs = cachesFolders.contains(PathPattern.comparablePath(of: child.deletingLastPathComponent()))+ && SystemCaches.isMacOSs(child.lastPathComponent)+ heldBack[child] = isMacOSs ? .keptByMacOS : HoldBack.seen(in: contents)}return Plan(removable: children.removable, inUse: children.inUse, leftToDeveloper: children.leftToDeveloper, sizes: sizes,diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SystemCaches.swift b/Packages/PeelCore/Sources/PeelCore/Space/SystemCaches.swiftnew file mode 100644index 00000000..bf39d037--- /dev/null+++ b/Packages/PeelCore/Sources/PeelCore/Space/SystemCaches.swift@@ -0,0 +1,26 @@+import Foundation+internal import PeelPrivileged++/// The folders in a Caches folder that macOS keeps for its own services, which may be using them at any moment.+enum SystemCaches {+ /// The ones not named `com.apple.`, each with the part of the sealed system that carries its name.+ static let named: [String: String] = [+ "AMSDataMigratorTool": "/System/Library/PrivateFrameworks/AppleMediaServices.framework"+ + "/Versions/A/Resources/AMSDataMigratorTool",+ "CloudKit": "/System/Library/Frameworks/CloudKit.framework",+ "containermanagerd": "/usr/libexec/containermanagerd",+ "FamilyCircle": "/System/Library/PrivateFrameworks/FamilyCircle.framework",+ "familycircled": "/System/Library/PrivateFrameworks/FamilyCircle.framework/Versions/A/Resources/familycircled",+ "GameKit": "/System/Library/Frameworks/GameKit.framework",+ "GeoServices": "/System/Library/PrivateFrameworks/GeoServices.framework",+ "homed": "/System/Library/PrivateFrameworks/HomeKitDaemon.framework/Support/homed",+ "HomeKit": "/System/Library/Frameworks/HomeKit.framework",+ "PassKit": "/System/Library/Frameworks/PassKit.framework",+ ]++ private static let lowercasedNames = Set(named.keys.map { $0.lowercased() })++ static func isMacOSs(_ name: String) -> Bool {+ ProtectedData.isApplesName(name) || lowercasedNames.contains(name.lowercased())+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swiftindex d7f19869..886ba323 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift@@ -93,6 +93,32 @@ struct SpaceRemovalTests {#expect(plan.leftToDeveloper.map(\.lastPathComponent) == ["Google"])}+ @Test func neverSelectsACacheMacOSKeepsForItself() async throws {+ let directory = try TemporaryDirectory()+ for name in ["com.apple.Spotlight", "CloudKit", "familycircled", "org.example.notes", "com.gone.app"] {+ try directory.file("home/Library/Caches/\(name)/data.db")+ }+ try directory.file("home/Library/Logs/com.apple.example/run.log")+ let logs = SpaceItem(+ id: "logs",+ category: .library,+ urls: [directory.url.appending(path: "home/Library/Logs", directoryHint: .isDirectory)],+ size: 0,+ handling: .trash+ )+ let names = { (urls: [URL]) in urls.map(\.lastPathComponent).sorted() }++ let caches = await SpaceRemoval.plan(for: item(directory), environment: environment(directory), running: [:])+ let logged = await SpaceRemoval.plan(for: logs, environment: environment(directory), running: [:])++ let all = ["CloudKit", "com.apple.Spotlight", "com.gone.app", "familycircled", "org.example.notes"]+ #expect(names(caches.removable) == all)+ #expect(names(Array(caches.suggested)) == ["com.gone.app", "org.example.notes"])+ let keptByMacOS = caches.heldBack.filter { $0.value == .keptByMacOS }.map(\.key)+ #expect(names(keptByMacOS) == ["CloudKit", "com.apple.Spotlight", "familycircled"])+ #expect(names(Array(logged.suggested)) == ["com.apple.example"])+ }+@Test func leavesAloneWhatAnOpenAppIsStillUsing() async throws {let directory = try TemporaryDirectory()try directory.file("home/Library/Caches/com.spotify.client/audio.db")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SystemCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SystemCachesTests.swiftnew file mode 100644index 00000000..d774aef5--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/SystemCachesTests.swift@@ -0,0 +1,20 @@+import Foundation+@testable import PeelCore+import Testing++struct SystemCachesTests {+ @Test func everyNameIsCarriedByAPartOfTheSealedSystem() {+ for (name, source) in SystemCaches.named {+ #expect(FileManager.default.fileExists(atPath: source), "\(name): \(source)")+ #expect(URL(filePath: source).deletingPathExtension().lastPathComponent == name, "\(name): \(source)")+ }+ }++ @Test func knowsApplesCachesByTheirNameOrTheSystemsOwn() {+ #expect(SystemCaches.isMacOSs("com.apple.Spotlight"))+ #expect(SystemCaches.isMacOSs("CloudKit"))+ #expect(SystemCaches.isMacOSs("cloudkit"))+ #expect(!SystemCaches.isMacOSs("pip"))+ #expect(!SystemCaches.isMacOSs("org.example.app"))+ }+}diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swiftindex b8c110b9..7b24c407 100644--- a/Peel/Views/Presentation.swift+++ b/Peel/Views/Presentation.swift@@ -200,6 +200,8 @@ extension HoldBack {"Not selected: only the name matches, and it sits inside a folder that belongs to macOS or to another installed app, which may be keeping it for itself."case .beyondTheHelper:"Left alone: only an administrator can move this, and Peel’s helper isn’t allowed to move it from here."+ case .keptByMacOS:+ "Not selected: macOS keeps this cache for its own services, which may be using it right now."}}}diff --git a/SAFETY.md b/SAFETY.mdindex f0474647..efd6e3d4 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -164,8 +164,9 @@ apps. It is removed only by Remove Peel, in Settings, which takes its helper andNever selected for you, even when found: Xcode's archives of the apps you built and the symbols it copied from yourdevices, both needed to read crash reports, model weights, the packages a tool keeps installed outside your projects,-virtual environments, the installers and boxes a tool keeps for you to install again, `/Users/Shared` (it belongs to-every account, not just yours), a project you worked on this week, a folder with a repository, a wallet, or a signing+virtual environments, the installers and boxes a tool keeps for you to install again, a cache macOS keeps for its+own services in `~/Library/Caches` (Spotlight's, iCloud's, the fonts'), `/Users/Shared` (it belongs to every account,+not just yours), a project you worked on this week, a folder with a repository, a wallet, or a signingkey inside, a folder macOS would not let Peel read, and a folder Peel could not measure in time. Those last two areshown with their size as "Unknown", never as zero, in every tool and in History once they are moved: a folder too big toread quickly may be exactly the one with work inside, and nothing is selected for you without saying how much it is. A