Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Leave what macOS keeps under a plain name to macOS

Țugui Dragoș7ff560d8b2ed
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 30e7e1a2..b3d5ddc9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -187,14 +187,19 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
- An app's page, `peel leftovers`, and `peel uninstall` no longer say Peel couldn't look inside a folder named by
another program's identifier, such as Microsoft AutoUpdate's cache in `/Library/Caches`: it holds nothing of the
app's.
+- An app named like something macOS keeps for its own services, such as `Knowledge` in Application Support,
+ `GeoServices` in Caches, `Assistant` in Logs, or `Logging` in `/Library/Preferences`, no longer takes it: the app's
+ page, `peel leftovers`, and `peel uninstall` leave it to macOS, whatever a Homebrew cask names.
#### Orphaned Files
- The folders a Spring Boot server's embedded Tomcat leaves in the temporary folder, named `tomcat.` with the port and a
number, are no longer taken for apps' files, each listed as a gone app of its own.
-- The folder macOS keeps for its push notification service, `ApplePushService` in `/Library/Application Support`, is no
- longer named among the folders Peel couldn't look inside, in Orphaned Files or on an app's page: only macOS can read
- it, and no other app's files are there.
+- The folders macOS keeps for its own services, such as `ApplePushService` in `/Library/Application Support`, are no
+ longer named among the folders Peel couldn't look inside, in Orphaned Files or on an app's page: only macOS reads
+ them, and no other app's files are there.
+- Something macOS keeps for its own services is no longer listed once an app of the same name is gone, such as
+ `Application Support/Knowledge` after an app called Knowledge.
- Lists what an app with a tool's identifier left while another such app is installed.
#### Orphaned Files and Storage
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
index dbee838b..b1670d8a 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
@@ -89,12 +89,15 @@ struct LeftoverMatcher: Sendable {
)
}
- /// This app's claim on the item called `fileName` in a location of `kind`, found at `url` when the caller knows it.
- func match(fileName: String, kind: SearchLocation.Kind, at url: URL? = nil) -> LeftoverMatch? {
+ /// This app's claim on the item called `fileName` in a location of `kind`, found at `url` when the caller knows it,
+ /// and `nested` when it sits below the location's own entries.
+ func match(
+ fileName: String, kind: SearchLocation.Kind, at url: URL? = nil, nested: Bool = false
+ ) -> LeftoverMatch? {
let key = Self.key(from: fileName, kind: kind)
// A name still hidden here is the system's own: `.GlobalPreferences.plist` is the global domain.
guard !key.hasPrefix(".") else { return nil }
- let candidate = Candidate(key)
+ let candidate = Candidate(key, isMacOSs: !nested && SystemFolders.keeps(fileName, in: kind))
guard let evidence = target.claim(for: candidate) else { return nil }
var sharedWith: Set<String> = []
@@ -276,15 +279,17 @@ extension LeftoverMatcher {
let normalized: String
/// The name without a version written right after it, normalized, for a folder kept for one release.
let withoutVersion: String?
+ /// True for a name only an app Apple signed may claim: one Apple gives its own, or one macOS keeps for its
+ /// services in the folder the item is directly in.
let isApple: Bool
var isLongEnoughToShare: Bool { normalized.count >= 4 }
- init(_ key: String) {
+ init(_ key: String, isMacOSs: Bool = false) {
self.key = key.lowercased()
normalized = Naming.normalized(key)
withoutVersion = Naming.withoutAttachedVersion(key).map(Naming.normalized)
- isApple = ProtectedData.isApplesName(key)
+ isApple = isMacOSs || ProtectedData.isApplesName(key)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
index 12985a22..e2cdffc9 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
@@ -279,9 +279,9 @@ public struct LeftoverScanner: Sendable {
// A browser's manifest is whoever's program it runs, whatever it is called.
url.deletingLastPathComponent().lastPathComponent.lowercased() == "nativemessaginghosts"
? runsSomethingInside(bundle, manifest: url)
- : Self.match(name, at: url, kind: kind, matcher: matcher, home: home)
+ : Self.match(name, at: url, kind: kind, matcher: matcher, home: home, nested: true)
}
- let search: NestedSearch.Findings<Found> = await NestedSearch.walk(inside: folders, limit: limit) {
+ let search: NestedSearch.Findings<Found> = await NestedSearch.walk(inside: folders, of: kind, limit: limit) {
url, name, parent, canLookInside in
let path = url.path(percentEncoded: false)
let match = matching(url, named: name)
@@ -346,7 +346,10 @@ public struct LeftoverScanner: Sendable {
private static func foldersAbove(
_ folders: some Collection<String>, kind: SearchLocation.Kind, matcher: LeftoverMatcher
) -> FoldersAbove {
- if folders.contains(where: { isSomebodyElses($0, kind: kind, matcher: matcher) }) { return .anotherApps }
+ let isMacOSs = folders.first.map { SystemFolders.keeps($0, in: kind) } ?? false
+ if isMacOSs || folders.contains(where: { isSomebodyElses($0, kind: kind, matcher: matcher) }) {
+ return .anotherApps
+ }
return folders.allSatisfy(matcher.namesTheAppOrItsMaker(folder:)) ? .itsOwn : .unknown
}
@@ -476,14 +479,15 @@ public struct LeftoverScanner: Sendable {
at url: URL,
kind: SearchLocation.Kind,
matcher: LeftoverMatcher,
- home: String
+ home: String,
+ nested: Bool = false
) -> LeftoverMatch? {
// A system extension macOS activated is its own to remove: it uninstalls one with the app it came in.
guard url.pathExtension.lowercased() != "systemextension" else { return nil }
if let updaters = matcher.updatersFolder(at: url, home: home) { return updaters }
if let named = matcher.productFolder(at: url, home: home) { return named }
let byName = DeclaredIdentifier.nameSaysNothing(of: url, kind: kind)
- ? nil : matcher.match(fileName: name, kind: kind, at: url)
+ ? nil : matcher.match(fileName: name, kind: kind, at: url, nested: nested)
guard byName == nil || DeclaredIdentifier.outranksTheName(of: url, kind: kind) else { return byName }
// `.elsewhere`, so no extension is taken off the identifier as if it were a file name.
let declared = DeclaredIdentifier.of(url, kind: kind).flatMap {
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/NestedSearch.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/NestedSearch.swift
index 5bc5062a..ebae2739 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/NestedSearch.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/NestedSearch.swift
@@ -35,11 +35,13 @@ enum NestedSearch {
/// and each listing is cheap.
static let folderLimit = 5_000
- /// Lists `folders`, and every folder inside them that `visit` asks to look inside, `depth` levels down and at most
- /// `limit` folders in all. `visit` is told whether a folder it asks to look inside would still be listed. A folder
- /// of Apple's own that cannot be listed is not returned, since it holds no other app's files.
+ /// Lists `folders`, the entries of a location of `kind`, and every folder inside them that `visit` asks to look
+ /// inside, `depth` levels down and at most `limit` folders in all. `visit` is told whether a folder it asks to look
+ /// inside would still be listed. A folder of Apple's own that cannot be listed is not returned, since it holds no
+ /// other app's files.
static func walk<Item>(
inside folders: [URL],
+ of kind: SearchLocation.Kind,
limit: Int,
visit: (_ entry: URL, _ name: String, _ parent: ParentAccess, _ canLookInside: Bool) async -> Step<Item>
) async -> Findings<Item> {
@@ -66,7 +68,7 @@ enum NestedSearch {
continue
} catch {
let name = folder.lastPathComponent
- if !ProtectedData.isApplesName(name), !SystemSupportFolders.isMacOSs(name) {
+ if !ProtectedData.isApplesName(name), level > 0 || !SystemFolders.keeps(name, in: kind) {
findings.unreadable.append(folder)
}
continue
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/SystemFolders.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/SystemFolders.swift
new file mode 100644
index 00000000..892c1849
--- /dev/null
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/SystemFolders.swift
@@ -0,0 +1,225 @@
+import Foundation
+
+/// What macOS keeps for its own services under a plain name in the Library folders Peel searches. No app claims one by
+/// its name, so an app called Knowledge never takes `Application Support/Knowledge`. Each name comes with what in the
+/// sealed system proves it.
+enum SystemFolders {
+ /// What in the sealed system proves that a name is macOS's.
+ enum Proof: Sendable {
+ /// A part of the sealed system called by the name: a framework, a program, or the sandbox profile of one.
+ case part(String)
+ /// A program or a sandbox profile of the sealed system that holds `naming`.
+ case file(String, naming: String)
+ /// An image in the dyld shared cache that holds `naming`.
+ case image(String, naming: String)
+ }
+
+ static let applicationSupport: [String: Proof] = [
+ "Accessibility": .file("/System/Library/ExtensionKit/Extensions/AccessibilitySettingsExtension.appex/Contents/MacOS/AccessibilitySettingsExtension", naming: "Library/Application Support/Accessibility"),
+ "AddressBook": .file("/System/Library/Sandbox/Profiles/com.apple.iMessage.addressbook.sb", naming: "/Library/Application Support/AddressBook"),
+ "Animoji": .file("/System/Library/Sandbox/Profiles/com.apple.avatarsd.sb", naming: "/Library/Application Support/Animoji"),
+ "App Store": .file("/System/Library/Frameworks/StoreKit.framework/Support/storekitagent", naming: "Library/Application Support/App Store"),
+ "Apple": .file("/System/Library/Sandbox/Profiles/com.apple.AssetCacheManagerService.sb", naming: "/Library/Application Support/Apple"),
+ "AppleIDAccountInfo": .file("/usr/libexec/sharingd", naming: "Library/Application Support/AppleIDAccountInfo"),
+ "ApplePushService": .part("/System/Library/PrivateFrameworks/ApplePushService.framework"),
+ "AppStore": .file("/System/Library/Sandbox/Profiles/com.apple.AppStoreDaemon.StorePrivilegedTaskService.sb", naming: "/Library/Application Support/AppStore"),
+ "AppStoreContent": .file("/System/Library/PrivateFrameworks/AppStoreDaemon.framework/Versions/A/XPCServices/com.apple.AppStoreDaemon.StorePrivilegedTaskService.xpc/Contents/MacOS/com.apple.AppStoreDaemon.StorePrivilegedTaskService", naming: "Library/Application Support/AppStoreContent"),
+ "assistantd": .file("/System/Library/Sandbox/Profiles/com.apple.assistantd.transcoded.sb", naming: "/Library/Application Support/assistantd"),
+ "bookdatastored": .file("/System/Library/PrivateFrameworks/BookDataStore.framework/Support/bookdatastored", naming: "Library/Application Support/bookdatastored"),
+ "BTServer": .file("/usr/sbin/bluetoothd", naming: "Library/Application Support/BTServer"),
+ "CallHistoryDB": .file("/System/Library/Sandbox/Profiles/com.apple.GameOverlayUI.sb", naming: "/Library/Application Support/CallHistoryDB"),
+ "Certificate Authority": .file("/usr/sbin/slapconfig", naming: "Library/Application Support/Certificate Authority"),
+ "CloudDocs": .file("/System/Library/Sandbox/Profiles/com.apple.CloudDocsDaemon.container-metadata-extractor.sb", naming: "/Library/Application Support/CloudDocs"),
+ "contactsd": .file("/System/Library/Sandbox/Profiles/com.apple.contactsd.sb", naming: "/Library/Application Support/contactsd"),
+ "CrashReporter": .file("/System/Library/CoreServices/SubmitDiagInfo", naming: "Library/Application Support/CrashReporter"),
+ "DifferentialPrivacy": .file("/System/Library/Sandbox/Profiles/com.apple.dprivacyd.agent.sb", naming: "/Library/Application Support/DifferentialPrivacy"),
+ "Directory Access": .file("/System/Library/CoreServices/Applications/Directory Utility.app/Contents/PlugIns/LDAPv3.daplug/Contents/MacOS/LDAPv3", naming: "Library/Application Support/Directory Access"),
+ "DiskImages": .part("/System/Library/PrivateFrameworks/DiskImages.framework"),
+ "DumpPanic": .file("/usr/libexec/DumpPanic", naming: "Library/Application Support/DumpPanic"),
+ "FaceTime": .file("/System/Library/Sandbox/Profiles/com.apple.FaceTime.FTConversationService.sb", naming: "/Library/Application Support/FaceTime"),
+ "familycircled": .file("/System/Library/Sandbox/Profiles/com.apple.familycircled.sb", naming: "/Library/Application Support/familycircled"),
+ "fdesetup": .file("/usr/bin/fdesetup", naming: "Library/Application Support/fdesetup"),
+ "FileProvider": .file("/System/Library/Sandbox/Profiles/com.apple.fileproviderd.sb", naming: "/Library/Application Support/FileProvider"),
+ "homeenergyd": .file("/System/Library/Sandbox/Profiles/com.apple.homeenergyd.sb", naming: "/Library/Application Support/homeenergyd"),
+ "icdd": .file("/System/Library/Sandbox/Profiles/com.apple.icdd.sb", naming: "/Library/Application Support/icdd"),
+ "iCloud": .part("/System/Library/CoreServices/iCloud.app"),
+ "identityservicesd": .file("/System/Library/Sandbox/Profiles/com.apple.identityservicesd.sb", naming: "/Library/Application Support/identityservicesd"),
+ "iLifeAssetManagement": .file("/System/Library/CoreServices/UAUPlugins/PhotosUserAccountUpdaterPlugin.bundle/Contents/MacOS/PhotosUserAccountUpdaterTool", naming: "Library/Application Support/iLifeAssetManagement"),
+ "iLifeMediaBrowser": .part("/System/Library/PrivateFrameworks/iLifeMediaBrowser.framework"),
+ "Knowledge": .file("/System/Library/Sandbox/Profiles/com.apple.knowledge-agent.sb", naming: "/Library/Application Support/Knowledge"),
+ "livefsd": .file("/System/Library/Sandbox/Profiles/com.apple.fskit.fskit_agent.sb", naming: "/Library/Application Support/livefsd"),
+ "locationaccessstored": .part("/usr/libexec/locationaccessstored"),
+ "Managed Background Assets Helper Service": .file("/System/Library/Sandbox/Profiles/com.apple.backgroundassets.managed.helper.service.sb", naming: "/Library/Application Support/Managed Background Assets Helper Service"),
+ "MobileSync": .file("/System/Library/PrivateFrameworks/StorageManagement.framework/PlugIns/iOSFilesStorageExtension.appex/Contents/MacOS/iOSFilesStorageExtension", naming: "Library/Application Support/MobileSync"),
+ "networkserviceproxy": .file("/System/Library/Sandbox/Profiles/com.apple.networkserviceproxy.sb", naming: "/Library/Application Support/networkserviceproxy"),
+ "Quick Look": .file("/System/Library/Sandbox/Profiles/com.apple.quicklook.ThumbnailsAgent.sb", naming: "/Library/Application Support/Quick Look"),
+ "Rapport": .file("/System/Library/Sandbox/Profiles/com.apple.rapportd.sb", naming: "/Library/Application Support/Rapport"),
+ "SESStorage": .file("/usr/libexec/seserviced", naming: "Library/Application Support/SESStorage"),
+ "SNLUOverrides.sqlite": .file("/System/Library/Sandbox/Profiles/com.apple.assistantd.transcoded.sb", naming: "/Library/Application Support/SNLUOverrides.sqlite"),
+ "SNLUOverrides.sqlite-shm": .file("/System/Library/Sandbox/Profiles/com.apple.assistantd.transcoded.sb", naming: "/Library/Application Support/SNLUOverrides.sqlite-shm"),
+ "SNLUOverrides.sqlite-wal": .file("/System/Library/Sandbox/Profiles/com.apple.assistantd.transcoded.sb", naming: "/Library/Application Support/SNLUOverrides.sqlite-wal"),
+ "SubmitDiagInfo": .file("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/DumpGPURestart", naming: "Library/Application Support/SubmitDiagInfo"),
+ "SyncServices": .file("/System/Library/Sandbox/Profiles/com.apple.suggestd.sb", naming: "/Library/Application Support/SyncServices"),
+ "transparencyd": .file("/System/Library/Sandbox/Profiles/com.apple.swtransparencyd.sb", naming: "/Library/Application Support/transparencyd"),
+ "videosubscriptionsd": .file("/System/Library/Sandbox/Profiles/com.apple.videosubscriptionsd.sb", naming: "/Library/Application Support/videosubscriptionsd"),
+ "voicememod": .file("/System/iOSSupport/System/Library/PrivateFrameworks/VoiceMemos.framework/Support/voicememod", naming: "Library/Application Support/voicememod"),
+ "XCTest": .file("/usr/libexec/testmanagerd", naming: "Library/Application Support/XCTest"),
+ ]
+
+ static let caches: [String: Proof] = [
+ "AMSDataMigratorTool": .part("/System/Library/PrivateFrameworks/AppleMediaServices.framework/Versions/A/Resources/AMSDataMigratorTool"),
+ "assessmentagent": .part("/usr/libexec/assessmentagent"),
+ "AudioComponentRegistrar": .part("/System/Library/Frameworks/AudioToolbox.framework/AudioComponentRegistrar"),
+ "AudioConverterService": .part("/System/Library/Frameworks/AudioToolbox.framework/XPCServices/AudioConverterService.xpc"),
+ "betaenrollmentagent": .part("/usr/libexec/betaenrollmentagent"),
+ "CloudKit": .part("/System/Library/Frameworks/CloudKit.framework"),
+ "ColorSync": .part("/System/Library/ColorSync"),
+ "containermanagerd": .part("/usr/libexec/containermanagerd"),
+ "contentlinkingd": .part("/System/Library/PrivateFrameworks/Synapse.framework/Support/contentlinkingd"),
+ "CSExattrCryptoService": .part("/System/Library/PrivateFrameworks/CSExattrCrypto.framework/Versions/A/XPCServices/CSExattrCryptoService.xpc"),
+ "Desktop Pictures": .part("/System/Library/Desktop Pictures"),
+ "diagnosticextensionsd": .part("/usr/libexec/diagnosticextensionsd"),
+ "duetexpertd": .part("/usr/libexec/duetexpertd"),
+ "FamilyCircle": .part("/System/Library/PrivateFrameworks/FamilyCircle.framework"),
+ "familycircled": .part("/System/Library/PrivateFrameworks/FamilyCircle.framework/Versions/A/Resources/familycircled"),
+ "gamed": .part("/usr/libexec/gamed"),
+ "GameKit": .part("/System/Library/Frameworks/GameKit.framework"),
+ "GameStoreKit": .part("/System/Library/PrivateFrameworks/GameStoreKit.framework"),
+ "GeoServices": .part("/System/Library/PrivateFrameworks/GeoServices.framework"),
+ "heard": .part("/System/Library/PrivateFrameworks/HearingCore.framework/heard"),
+ "homed": .part("/System/Library/PrivateFrameworks/HomeKitDaemon.framework/Support/homed"),
+ "HomeKit": .part("/System/Library/Frameworks/HomeKit.framework"),
+ "icdd": .part("/System/Library/Image Capture/Support/icdd"),
+ "itunescloudd": .part("/System/Library/PrivateFrameworks/iTunesCloud.framework/Support/itunescloudd"),
+ "mediaanalysisd-access": .part("/System/Library/PrivateFrameworks/MediaAnalysisAccess.framework/Versions/A/XPCServices/mediaanalysisd-access.xpc"),
+ "metrickitd": .part("/usr/libexec/metrickitd"),
+ "mobiletimerd": .part("/System/Library/PrivateFrameworks/MobileTimer.framework/Executables/mobiletimerd"),
+ "PassKit": .part("/System/Library/Frameworks/PassKit.framework"),
+ "proactived": .part("/usr/libexec/proactived"),
+ "ptpcamerad": .part("/usr/libexec/ptpcamerad"),
+ "StatusKitAgent": .part("/System/Library/PrivateFrameworks/StatusKit.framework/StatusKitAgent"),
+ "studentd": .part("/usr/libexec/studentd"),
+ "talagent": .part("/System/Library/CoreServices/talagent"),
+ "watchlistd": .part("/System/Library/PrivateFrameworks/WatchListKit.framework/Support/watchlistd"),
+ ]
+
+ static let logs: [String: Proof] = [
+ "Accounts": .file("/System/Library/Sandbox/Profiles/frameworks.sb", naming: "/Library/Logs/Accounts"),
+ "AppleSSE.log": .file("/System/Library/Sandbox/Profiles/com.apple.passd.sb", naming: "/Library/Logs/AppleSSE.log"),
+ "AppleSupport": .file("/System/Library/CoreServices/Setup Assistant.app/Contents/MacOS/Setup Assistant", naming: "Library/Logs/AppleSupport"),
+ "Assistant": .file("/System/Library/Sandbox/Profiles/com.apple.assistantd.sb", naming: "/Library/Logs/Assistant"),
+ "ats.log": .file("/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Resources/libATSServer.dylib", naming: "Library/Logs/ats.log"),
+ "AutoBugCapture": .file("/System/Library/PrivateFrameworks/CacheDelete.framework/deleted_helper", naming: "Library/Logs/AutoBugCapture"),
+ "Baseband": .file("/System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter", naming: "Library/Logs/Baseband"),
+ "BioLog": .file("/usr/libexec/biometrickitd", naming: "Library/Logs/BioLog"),
+ "Bluetooth": .file("/usr/share/sandbox/bluetoothd.sb", naming: "/Library/Logs/Bluetooth"),
+ "CallHistory": .file("/System/Library/Sandbox/Profiles/com.apple.assistantd.transcoded.sb", naming: "/Library/Logs/CallHistory"),
+ "CoreCapture": .file("/usr/libexec/wifivelocityd", naming: "Library/Logs/CoreCapture"),
+ "CoreStorage.log": .file("/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs_preflight_converter", naming: "Library/Logs/CoreStorage.log"),
+ "CoreTelephonyTrace": .file("/System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter", naming: "Library/Logs/CoreTelephonyTrace"),
+ "CoreTelephonyTraceScratch": .file("/System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter", naming: "Library/Logs/CoreTelephonyTraceScratch"),
+ "CrashReporter": .file("/usr/libexec/DumpPanic", naming: "/Library/Logs/CrashReporter"),
+ "DiagnosticReports": .file("/System/Library/CoreServices/SubmitDiagInfo", naming: "Library/Logs/DiagnosticReports"),
+ "DiscRecording.log": .file("/System/Library/SystemProfiler/SPLogsReporter.spreporter/Contents/MacOS/SPLogsReporter", naming: "Library/Logs/DiscRecording.log"),
+ "findmydeviced": .file("/usr/libexec/findmydeviced", naming: "Library/Logs/findmydeviced"),
+ "fsck_apfs.log": .file("/System/Library/Filesystems/apfs.fs/Contents/Resources/fsck_apfs", naming: "Library/Logs/fsck_apfs.log"),
+ "fsck_hfs.log": .file("/System/Library/Filesystems/hfs.fs/Contents/Resources/fsck_hfs", naming: "Library/Logs/fsck_hfs.log"),
+ "hidfw-crashlogs": .file("/usr/libexec/sysdiagnosed", naming: "/Library/Logs/hidfw-crashlogs"),
+ "intelligentroutingd": .file("/System/Library/Sandbox/Profiles/com.apple.intelligentroutingd.sb", naming: "/Library/Logs/intelligentroutingd"),
+ "InternetAccounts": .file("/System/Library/Sandbox/Profiles/frameworks.sb", naming: "/Library/Logs/InternetAccounts"),
+ "IOKit": .file("/System/Library/CoreServices/powerd.bundle/powerd", naming: "Library/Logs/IOKit"),
+ "khwm.log": .file("/usr/libexec/sysstatuscheck", naming: "Library/Logs/khwm.log"),
+ "LKDC-setup.log": .file("/usr/libexec/configureLocalKDC", naming: "/Library/Logs/LKDC-setup.log"),
+ "ManagedClient": .file("/System/Library/CoreServices/SecurityAgentPlugins/MCXMechanism.bundle/Contents/MacOS/MCXMechanism", naming: "Library/Logs/ManagedClient"),
+ "MCXTools.log": .file("/usr/libexec/mcxalr", naming: "/Library/Logs/MCXTools.log"),
+ "MDM": .file("/System/Library/ExtensionKit/Extensions/ProfilesSettingsExt.appex/Contents/MacOS/ProfilesSettingsExt", naming: "Library/Logs/MDM"),
+ "MDMSim": .file("/usr/libexec/mdmclient", naming: "Library/Logs/MDMSim"),
+ "mdworker": .file("/usr/share/sandbox/mdworker-mail.sb", naming: "/Library/Logs/mdworker"),
+ "Metal": .file("/System/Library/Sandbox/Profiles/com.apple.mtlcompilerservice.sb", naming: "/Library/Logs/Metal"),
+ "milod": .file("/System/Library/Sandbox/Profiles/com.apple.milod.sb", naming: "/Library/Logs/milod"),
+ "mobileactivationd": .file("/usr/libexec/mobileactivationd", naming: "Library/Logs/mobileactivationd"),
+ "MobileInstallation": .part("/System/Library/PrivateFrameworks/MobileInstallation.framework"),
+ "PasswordService": .file("/usr/sbin/PasswordService", naming: "Library/Logs/PasswordService"),
+ "PersonalizationPortrait": .file("/System/Library/Sandbox/Profiles/com.apple.suggestd.sb", naming: "/Library/Logs/PersonalizationPortrait"),
+ "PhotosLegacyUpgrade.aapbz": .file("/System/Library/PrivateFrameworks/CloudPhotoLibrary.framework/Versions/A/XPCServices/com.apple.Photos.CPLDiagnose.xpc/Contents/MacOS/com.apple.Photos.CPLDiagnose", naming: "Library/Logs/PhotosLegacyUpgrade.aapbz"),
+ "PhotosLegacyUpgradeCompanion.aapbz": .file("/System/Library/PrivateFrameworks/CloudPhotoLibrary.framework/Versions/A/XPCServices/com.apple.Photos.CPLDiagnose.xpc/Contents/MacOS/com.apple.Photos.CPLDiagnose", naming: "Library/Logs/PhotosLegacyUpgradeCompanion.aapbz"),
+ "photoslibraryupgrade.log": .file("/System/Library/PrivateFrameworks/PhotoLibraryServicesCore.framework/Versions/A/XPCServices/com.apple.Photos.Migration.xpc/Contents/MacOS/com.apple.Photos.Migration", naming: "Library/Logs/photoslibraryupgrade.log"),
+ "PhotosSearch.aapbz": .file("/System/Library/PrivateFrameworks/CloudPhotoLibrary.framework/Versions/A/XPCServices/com.apple.Photos.CPLDiagnose.xpc/Contents/MacOS/com.apple.Photos.CPLDiagnose", naming: "Library/Logs/PhotosSearch.aapbz"),
+ "PhotosUpgrade.aapbz": .file("/System/Library/PrivateFrameworks/CloudPhotoLibrary.framework/Versions/A/XPCServices/com.apple.Photos.CPLDiagnose.xpc/Contents/MacOS/com.apple.Photos.CPLDiagnose", naming: "Library/Logs/PhotosUpgrade.aapbz"),
+ "PhotosUpgrade.log": .file("/System/Library/PrivateFrameworks/CloudPhotoLibrary.framework/Versions/A/XPCServices/com.apple.Photos.CPLDiagnose.xpc/Contents/MacOS/com.apple.Photos.CPLDiagnose", naming: "Library/Logs/PhotosUpgrade.log"),
+ "PhotosUpgradeCompanion.log": .file("/System/Library/PrivateFrameworks/CloudPhotoLibrary.framework/Versions/A/XPCServices/com.apple.Photos.CPLDiagnose.xpc/Contents/MacOS/com.apple.Photos.CPLDiagnose", naming: "Library/Logs/PhotosUpgradeCompanion.log"),
+ "pipelined": .file("/usr/libexec/locationd", naming: "Library/Logs/pipelined"),
+ "PrivacyPreservingMeasurement": .file("/System/Library/Sandbox/Profiles/com.apple.dprivacyd.agent.sb", naming: "/Library/Logs/PrivacyPreservingMeasurement"),
+ "ProtectedCloudStorage.log": .file("/usr/share/sandbox/com.apple.cloudd.sb", naming: "/Library/Logs/ProtectedCloudStorage.log"),
+ "recoverylogd": .part("/System/Library/Sandbox/Profiles/recoverylogd.sb"),
+ "RTCReporting": .file("/System/Library/PrivateFrameworks/AVConference.framework/PlugIns/com.apple.AVConference.Diagnostic.appex/Contents/MacOS/com.apple.AVConference.Diagnostic", naming: "Library/Logs/RTCReporting"),
+ "RTCReports": .file("/System/Library/Sandbox/Profiles/com.apple.rtcreportingd.sb", naming: "/Library/Logs/RTCReports"),
+ "SiriTTSService": .file("/System/Library/Sandbox/Profiles/com.apple.sirittsd.sb", naming: "/Library/Logs/SiriTTSService"),
+ "SiriTTSTrainer": .file("/System/Library/Sandbox/Profiles/com.apple.SiriTTSTrainingAgent.sb", naming: "/Library/Logs/SiriTTSTrainer"),
+ "slapconfig.log": .file("/usr/sbin/slapconfig", naming: "Library/Logs/slapconfig.log"),
+ "SMSMigrator": .file("/System/Library/Sandbox/Profiles/com.apple.imdpersistence.IMDPersistenceAgent.sb", naming: "/Library/Logs/SMSMigrator"),
+ "Software Update.log": .file("/System/Library/SystemProfiler/SPLogsReporter.spreporter/Contents/MacOS/SPLogsReporter", naming: "Library/Logs/Software Update.log"),
+ "Touch": .file("/System/Library/HIDPlugins/ServicePlugins/HSTouchHIDService.plugin/Contents/MacOS/HSTouchHIDService", naming: "Library/Logs/Touch"),
+ "Trial": .file("/System/Library/Sandbox/Profiles/com.apple.triald.sb", naming: "/Library/Logs/Trial"),
+ "Ubiquity": .file("/System/Library/Sandbox/Profiles/com.apple.bird.sb", naming: "/Library/Logs/Ubiquity"),
+ "vinylscratch": .file("/System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter", naming: "Library/Logs/vinylscratch"),
+ "VoiceTrigger": .file("/System/Library/Sandbox/Profiles/com.apple.corespeechd.sb", naming: "/Library/Logs/VoiceTrigger"),
+ "WebDAVFileSharing.log": .file("/usr/libexec/wfs/webdavsharing_mapper", naming: "Library/Logs/WebDAVFileSharing.log"),
+ "WindowServer": .file("/usr/libexec/sysdiagnosed", naming: "/Library/Logs/WindowServer"),
+ "Xsan": .file("/System/Library/Filesystems/acfs.fs/Contents/Resources/acfs.util", naming: "/Library/Logs/Xsan"),
+ ]
+
+ static let preferences: [String: Proof] = [
+ "analyticsd.plist": .file("/System/Library/Sandbox/Profiles/com.apple.analyticsd.sb", naming: "/Library/Preferences/analyticsd.plist"),
+ "Audio": .file("/System/Library/Sandbox/Profiles/com.apple.audio.coreaudiod.sb", naming: "/Library/Preferences/Audio"),
+ "Bluetooth": .file("/usr/sbin/bluetoothd", naming: "Library/Preferences/Bluetooth"),
+ "CD Info.cidb": .file("/System/Library/Filesystems/cddafs.fs/Contents/Resources/mount_cddafs", naming: "Library/Preferences/CD Info.cidb"),
+ "ContextStoreAgent.plist": .file("/System/Library/Sandbox/Profiles/com.apple.ContextStoreAgent.sb", naming: "/Library/Preferences/ContextStoreAgent.plist"),
+ "csidata": .file("/System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter", naming: "Library/Preferences/csidata"),
+ "diagnostics_agent.plist": .part("/System/Library/CoreServices/diagnostics_agent"),
+ "DirectoryService": .file("/System/Library/Frameworks/OpenDirectory.framework/odmigrationtool", naming: "Library/Preferences/DirectoryService"),
+ "familycircled.plist": .part("/System/Library/PrivateFrameworks/FamilyCircle.framework/Versions/A/Resources/familycircled"),
+ "FeatureFlags": .file("/usr/libexec/init_featureflags", naming: "Library/Preferences/FeatureFlags"),
+ "GeoServices": .part("/System/Library/PrivateFrameworks/GeoServices.framework"),
+ "knowledge-agent.plist": .file("/System/Library/Sandbox/Profiles/com.apple.knowledge-agent.sb", naming: "/Library/Preferences/knowledge-agent.plist"),
+ "Logging": .file("/usr/libexec/sysdiagnosed", naming: "Library/Preferences/Logging"),
+ "loginwindow.plist": .part("/System/Library/CoreServices/loginwindow.app"),
+ "mbuseragent.plist": .part("/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/mbuseragent"),
+ "mdworker.plist": .file("/usr/share/sandbox/mdworker.sb", naming: "/Library/Preferences/mdworker.plist"),
+ "MobileMeAccounts.plist": .file("/System/Library/Sandbox/Profiles/frameworks.sb", naming: "(preference-domain \"MobileMeAccounts\")"),
+ "networkserviceproxy.plist": .file("/System/Library/Sandbox/Profiles/com.apple.networkserviceproxy.sb", naming: "/Library/Preferences/networkserviceproxy.plist"),
+ "nfcd.plist": .file("/System/Library/Sandbox/Profiles/nfcd.sb", naming: "/Library/Preferences/nfcd.plist"),
+ "no_backup": .file("/System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter", naming: "no_backup/commcenter_runtime_storage"),
+ "OpenDirectory": .file("/System/Library/Sandbox/Profiles/com.apple.opendirectoryd-deny-default.sb", naming: "/Library/Preferences/OpenDirectory"),
+ "opendirectoryd.plist": .file("/System/Library/Sandbox/Profiles/com.apple.opendirectoryd-deny-default.sb", naming: "/Library/Preferences/opendirectoryd.plist"),
+ "pbs.plist": .part("/System/Library/CoreServices/pbs"),
+ "ProtectedCloudStorage": .part("/System/Library/PrivateFrameworks/ProtectedCloudStorage.framework"),
+ "rtcreportingd.plist": .file("/System/Library/Sandbox/Profiles/com.apple.rtcreportingd.sb", naming: "/Library/Preferences/rtcreportingd.plist"),
+ "sharedfilelistd.plist": .part("/System/Library/CoreServices/sharedfilelistd"),
+ "SystemConfiguration": .file("/usr/libexec/sysdiagnosed", naming: "Library/Preferences/SystemConfiguration"),
+ "TokenBucketRateLimiter.plist": .image("/System/Library/PrivateFrameworks/SpotlightKnowledgeDaemon.framework/Versions/A/SpotlightKnowledgeDaemon", naming: "TokenBucketRateLimiter"),
+ "Xsan": .file("/System/Library/ConfigurationProfiles/PlugIns/xsanplugin.profileDomainPlugin/Contents/MacOS/xsanplugin", naming: "Library/Preferences/Xsan"),
+ ]
+
+ /// Whether macOS keeps an item called `fileName` for its own services in a folder of `kind`. A process keeps its
+ /// caches, its HTTP storage and its temporary items under the same name.
+ static func keeps(_ fileName: String, in kind: SearchLocation.Kind) -> Bool {
+ let names = switch kind {
+ case .applicationSupport: applicationSupportNames
+ case .caches, .httpStorages, .temporaryItems: cachesNames
+ case .logs: logsNames
+ case .preferences: preferencesNames
+ default: Set<String>()
+ }
+ return names.contains(fileName.lowercased())
+ }
+
+ private static let applicationSupportNames = lowercased(applicationSupport)
+ private static let cachesNames = lowercased(caches)
+ private static let logsNames = lowercased(logs)
+ private static let preferencesNames = lowercased(preferences)
+
+ private static func lowercased(_ list: [String: Proof]) -> Set<String> {
+ Set(list.keys.map { $0.lowercased() })
+ }
+}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/SystemSupportFolders.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/SystemSupportFolders.swift
deleted file mode 100644
index 34637325..00000000
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/SystemSupportFolders.swift
+++ /dev/null
@@ -1,15 +0,0 @@
-import Foundation
-
-/// What macOS keeps in an Application Support folder for its own services, each name with the part of the sealed
-/// system that carries it, as `SystemCaches` does for caches.
-enum SystemSupportFolders {
- static let named: [String: String] = [
- "ApplePushService": "/System/Library/PrivateFrameworks/ApplePushService.framework",
- ]
-
- private static let lowercasedNames = Set(named.keys.map { $0.lowercased() })
-
- static func isMacOSs(_ name: String) -> Bool {
- lowercasedNames.contains(name.lowercased())
- }
-}
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
index e53bd860..02c92131 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
@@ -605,7 +605,7 @@ public struct OrphanScanner: Sendable {
) async -> String? {
let name = url.lastPathComponent
guard
- namedPlaces.contains(kind), !isSensitive(fileName: name),
+ namedPlaces.contains(kind), !isSensitive(fileName: name), !SystemFolders.keeps(name, in: kind),
let app = goneNames[name.lowercased()],
!ownership.isClaimed(fileName: name, kind: kind, identifier: app),
!ownership.anInstalledAppsNameHolds(fileName: name, kind: kind)
@@ -704,6 +704,7 @@ public struct OrphanScanner: Sendable {
// an app's identifier, so only what came with an app Peel saw go is listed there.
let inside: NestedSearch.Findings<Candidate> = await NestedSearch.walk(
inside: nobodysFolders,
+ of: location.kind,
limit: nestedFolderLimit
) { url, _, parent, canLookInside in
guard isAFileAFolderOrALink(url), !ProtectedData.refuses(url.path(percentEncoded: false), home: home),
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index fc878a6a..0ead3656 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -254,10 +254,13 @@ public struct Uninstallation: Sendable {
let bundle = PathPattern.comparablePath(of: app.url)
let home = PathPattern.comparablePath(of: environment.homeDirectory)
for item in evidence.items where !exclusions.excludes(item.url) && !isAtOrInside(bundle, item.url) {
- // What one of Apple's packages installed is Apple's, whatever a cask says.
- if !isAtOrInside(home, item.url), await installedByApple(item.url) { continue }
let place = place(of: item.url, in: environment)
- let own = matcher.match(fileName: item.url.lastPathComponent, kind: place.kind, at: item.url)
+ // Whatever a cask says, what macOS keeps for itself or one of Apple's packages installed is Apple's.
+ if place.components.count == 1, SystemFolders.keeps(item.url.lastPathComponent, in: place.kind) { continue }
+ if !isAtOrInside(home, item.url), await installedByApple(item.url) { continue }
+ let own = matcher.match(
+ fileName: item.url.lastPathComponent, kind: place.kind, at: item.url, nested: place.components.count > 1
+ )
// Every folder on the way counts: a path inside a folder another app claims is not this app's alone.
let claims = place.components.map { matcher.othersClaiming(fileName: $0, kind: place.kind) }
let leftover = await LeftoverScanner.leftover(
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift
index 2ffa68b8..69cd1f20 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift
@@ -472,7 +472,7 @@ public enum SpaceInventory {
/// Whether macOS keeps `name` for its own services in a folder every account shares.
static func isMacOSsOwn(_ name: String) -> Bool {
- SystemCaches.isMacOSs(name) || SystemLogs.isMacOSs(name)
+ SystemCaches.isMacOSs(name) || SystemFolders.keeps(name, in: .logs)
}
private static func folders(in parent: URL) -> [URL] {
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SystemCaches.swift b/Packages/PeelCore/Sources/PeelCore/Space/SystemCaches.swift
index 9fa6103c..b33310fe 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/SystemCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/SystemCaches.swift
@@ -3,51 +3,8 @@ internal import PeelPrivileged
/// The folders in a Caches folder that macOS keeps for its own services, which may be using them at any moment.
struct 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",
- "assessmentagent": "/usr/libexec/assessmentagent",
- "AudioComponentRegistrar": "/System/Library/Frameworks/AudioToolbox.framework/AudioComponentRegistrar",
- "AudioConverterService": "/System/Library/Frameworks/AudioToolbox.framework/XPCServices/AudioConverterService.xpc",
- "betaenrollmentagent": "/usr/libexec/betaenrollmentagent",
- "CloudKit": "/System/Library/Frameworks/CloudKit.framework",
- "ColorSync": "/System/Library/ColorSync",
- "containermanagerd": "/usr/libexec/containermanagerd",
- "contentlinkingd": "/System/Library/PrivateFrameworks/Synapse.framework/Support/contentlinkingd",
- "CSExattrCryptoService": "/System/Library/PrivateFrameworks/CSExattrCrypto.framework/Versions/A/XPCServices"
- + "/CSExattrCryptoService.xpc",
- "Desktop Pictures": "/System/Library/Desktop Pictures",
- "diagnosticextensionsd": "/usr/libexec/diagnosticextensionsd",
- "duetexpertd": "/usr/libexec/duetexpertd",
- "FamilyCircle": "/System/Library/PrivateFrameworks/FamilyCircle.framework",
- "familycircled": "/System/Library/PrivateFrameworks/FamilyCircle.framework/Versions/A/Resources/familycircled",
- "gamed": "/usr/libexec/gamed",
- "GameKit": "/System/Library/Frameworks/GameKit.framework",
- "GameStoreKit": "/System/Library/PrivateFrameworks/GameStoreKit.framework",
- "GeoServices": "/System/Library/PrivateFrameworks/GeoServices.framework",
- "heard": "/System/Library/PrivateFrameworks/HearingCore.framework/heard",
- "homed": "/System/Library/PrivateFrameworks/HomeKitDaemon.framework/Support/homed",
- "HomeKit": "/System/Library/Frameworks/HomeKit.framework",
- "icdd": "/System/Library/Image Capture/Support/icdd",
- "itunescloudd": "/System/Library/PrivateFrameworks/iTunesCloud.framework/Support/itunescloudd",
- "mediaanalysisd-access": "/System/Library/PrivateFrameworks/MediaAnalysisAccess.framework/Versions/A/XPCServices"
- + "/mediaanalysisd-access.xpc",
- "metrickitd": "/usr/libexec/metrickitd",
- "mobiletimerd": "/System/Library/PrivateFrameworks/MobileTimer.framework/Executables/mobiletimerd",
- "PassKit": "/System/Library/Frameworks/PassKit.framework",
- "proactived": "/usr/libexec/proactived",
- "ptpcamerad": "/usr/libexec/ptpcamerad",
- "StatusKitAgent": "/System/Library/PrivateFrameworks/StatusKit.framework/StatusKitAgent",
- "studentd": "/usr/libexec/studentd",
- "talagent": "/System/Library/CoreServices/talagent",
- "watchlistd": "/System/Library/PrivateFrameworks/WatchListKit.framework/Support/watchlistd",
- ]
-
- private static let lowercasedNames = Set(named.keys.map { $0.lowercased() })
-
static func isMacOSs(_ name: String) -> Bool {
- ProtectedData.isApplesName(name) || lowercasedNames.contains(name.lowercased())
+ ProtectedData.isApplesName(name) || SystemFolders.keeps(name, in: .caches)
}
private let cachesFolders: Set<String>
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SystemLogs.swift b/Packages/PeelCore/Sources/PeelCore/Space/SystemLogs.swift
deleted file mode 100644
index 8b339bca..00000000
--- a/Packages/PeelCore/Sources/PeelCore/Space/SystemLogs.swift
+++ /dev/null
@@ -1,20 +0,0 @@
-import Foundation
-
-/// What macOS writes in the Logs folder at the top of the disk for its own services, each with the part of the
-/// sealed system that names that path.
-enum SystemLogs {
- static let named: [String: String] = [
- "CrashReporter": "/usr/libexec/DumpPanic",
- "hidfw-crashlogs": "/usr/libexec/sysdiagnosed",
- "LKDC-setup.log": "/usr/libexec/configureLocalKDC",
- "MCXTools.log": "/usr/libexec/mcxalr",
- "WindowServer": "/usr/libexec/sysdiagnosed",
- "Xsan": "/System/Library/Filesystems/acfs.fs/Contents/Resources/acfs.util",
- ]
-
- private static let lowercasedNames = Set(named.keys.map { $0.lowercased() })
-
- static func isMacOSs(_ name: String) -> Bool {
- lowercasedNames.contains(name.lowercased())
- }
-}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CaskEvidenceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CaskEvidenceTests.swift
index 2e331ad9..15b78e69 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CaskEvidenceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CaskEvidenceTests.swift
@@ -377,4 +377,28 @@ struct CaskEvidenceTests {
#expect(leftovers.first?.match.sharedWith == ["com.vendor.shared"])
#expect(leftovers.first?.match.isRecommended == false)
}
+
+ @Test func leavesOutACaskPathThatIsAFolderMacOSKeeps() async throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ try directory.file("home/Library/Application Support/Knowledge/knowledgeC.db")
+ try directory.directory("home/Library/Caches/org.example.knowledge")
+ let cask = HomebrewPackage(name: "knowledge", kind: .cask, appNames: ["Knowledge.app"], leftoverPatterns: [
+ "~/Library/Application Support/Knowledge", "~/Library/Caches/org.example.knowledge",
+ ])
+ let app = InstalledApp(
+ url: URL(filePath: "/Applications/Knowledge.app"), bundleIdentifier: "org.example.knowledge", name: "Knowledge"
+ )
+ let evidence = try #require(CaskEvidence.evidence(for: app, casks: [cask], home: home))
+
+ let leftovers = await Uninstallation.caskLeftovers(
+ evidence,
+ app: app,
+ exclusions: .none,
+ matcher: LeftoverMatcher(app: app, installedApps: [app]),
+ environment: environment(home)
+ )
+
+ #expect(leftovers.map(\.url.lastPathComponent) == ["org.example.knowledge"])
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
index 68c7d22e..db72e2b6 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
@@ -700,4 +700,17 @@ struct LeftoverMatcherTests {
let massive = app("com.native-instruments.massive", name: "Massive")
#expect(match("Massive.vst3", in: .plugIns, for: serum, with: [massive]) == nil)
}
+
+ @Test func aFolderMacOSKeepsUnderAPlainNameIsNoAppsByThatName() {
+ let knowledge = app("org.example.knowledge", name: "Knowledge")
+ let assistant = app("org.example.assistant", name: "Assistant")
+ let logging = app("org.example.logging", name: "Logging")
+
+ #expect(match("Knowledge", in: .applicationSupport, for: knowledge) == nil)
+ #expect(match("Assistant", in: .logs, for: assistant) == nil)
+ #expect(match("GeoServices", in: .caches, for: app("org.example.geoservices", name: "GeoServices")) == nil)
+ #expect(match("Logging", in: .preferences, for: logging) == nil)
+ #expect(match("Knowledge", in: .caches, for: knowledge)?.isRecommended == true)
+ #expect(match("Assistant", in: .applicationSupport, for: assistant)?.isRecommended == true)
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index 4e94e866..a9140e5d 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -516,8 +516,9 @@ struct LeftoverScannerTests {
for folder in makers {
#expect(found[folder]?.match.isRecommended == true, "\(folder)")
}
+ #expect(found["SyncServices/Hollow"]?.match.heldBack == .insideAnotherAppsFolder)
+ #expect(found["tool/telemetry/hollow"]?.match.heldBack == .namedLikeTheApp)
for folder in others {
- #expect(found[folder]?.match.heldBack == .namedLikeTheApp, "\(folder)")
#expect(found[folder]?.match.isRecommended == false, "\(folder)")
}
}
@@ -2125,4 +2126,29 @@ struct LeftoverScannerTests {
<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>\(bundleIdentifier)</string></dict></plist>
""".utf8)
}
+
+ @Test func anUninstallLeavesWhatMacOSKeepsUnderTheAppsName() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/Library/Application Support/Knowledge/knowledgeC.db")
+ try directory.file("home/Library/Caches/Knowledge/cache.db")
+ try directory.file("home/Library/Application Support/SyncServices/Knowledge/data.db")
+ let environment = SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ )
+ let app = InstalledApp(
+ url: try directory.directory("root/Applications/Knowledge.app"),
+ bundleIdentifier: "org.example.knowledge",
+ name: "Knowledge"
+ )
+
+ let plan = await Uninstallation.prepare(app, installedApps: [app], environment: environment)
+
+ let found = Dictionary(uniqueKeysWithValues: plan.scan.leftovers.map {
+ ("\($0.url.deletingLastPathComponent().lastPathComponent)/\($0.url.lastPathComponent)", $0)
+ })
+ #expect(Set(found.keys) == ["Caches/Knowledge", "SyncServices/Knowledge"])
+ #expect(found["Caches/Knowledge"]?.match.isRecommended == true)
+ #expect(found["SyncServices/Knowledge"]?.match.heldBack == .insideAnotherAppsFolder)
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index c882fcd8..39bb18fa 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -1543,4 +1543,36 @@ struct OrphanScannerTests {
#expect(scan.groups.flatMap(\.items).map(\.url.lastPathComponent) == ["com.gone.app"])
}
+
+ @Test func neverNamesAFolderMacOSKeepsAfterAnAppThatLeft() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/Library/Application Support/Knowledge/knowledgeC.db")
+ try directory.file("home/Library/Caches/Knowledge/cache.db")
+ let knowledge = RememberedApp(
+ bundleIdentifier: "org.example.knowledge", name: "Knowledge", teamIdentifier: nil,
+ lastSeen: .now.addingTimeInterval(-90 * 24 * 60 * 60), lastPath: "/Applications/Knowledge.app"
+ )
+
+ let groups = await scanner(in: directory).scan(installedApps: installed, remembered: [knowledge]).groups
+
+ #expect(groups.flatMap(\.items).map { "\($0.kind.rawValue)/\($0.url.lastPathComponent)" } == ["caches/Knowledge"])
+ }
+
+ @Test(.permissionsHold) func saysNothingOfALogFolderOfMacOSsOwnItCouldNotRead() async throws {
+ let directory = try TemporaryDirectory()
+ let folders = ["Assistant", "Knowledge"]
+ for folder in folders {
+ try directory.file("home/Library/Logs/\(folder)/org.example.mixer/mixer.log")
+ try directory.setPermissions(0, of: "home/Library/Logs/\(folder)")
+ }
+ defer {
+ for folder in folders {
+ try? directory.setPermissions(0o755, of: "home/Library/Logs/\(folder)")
+ }
+ }
+
+ let scan = await scanner(in: directory).scan(installedApps: installed)
+
+ #expect(scan.unreadableLocations.map(\.url.lastPathComponent) == ["Knowledge"])
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SharedCache.swift b/Packages/PeelCore/Tests/PeelCoreTests/SharedCache.swift
new file mode 100644
index 00000000..f7870cfa
--- /dev/null
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SharedCache.swift
@@ -0,0 +1,57 @@
+import Foundation
+
+/// The images of this Mac's dyld shared cache, read from the cache's own headers (`dyld_cache_format.h`): the main
+/// file's table of image text says where each image's `__TEXT` is, and each file's mappings say which file holds it.
+enum SharedCache {
+ private static let folder = URL(filePath: "/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld")
+ #if arch(arm64)
+ private static let name = "dyld_shared_cache_arm64e"
+ #else
+ private static let name = "dyld_shared_cache_x86_64h"
+ #endif
+
+ /// Whether the `__TEXT` of the image at `path` holds `text`.
+ static func image(_ path: String, holds text: String) throws -> Bool {
+ let main = try Data(contentsOf: folder.appending(path: name))
+ let table = Int(main.number(UInt64.self, at: 0x88))
+ for index in 0..<Int(main.number(UInt64.self, at: 0x90)) {
+ let entry = table + index * 32
+ guard main.cString(at: Int(main.number(UInt32.self, at: entry + 28))) == path else { continue }
+ let address = main.number(UInt64.self, at: entry + 16), size = main.number(UInt32.self, at: entry + 24)
+ return try bytes(at: address, size: size).range(of: Data(text.utf8)) != nil
+ }
+ return false
+ }
+
+ private static func bytes(at address: UInt64, size: UInt32) throws -> Data {
+ let files = try FileManager.default.contentsOfDirectory(atPath: folder.path(percentEncoded: false)).filter {
+ $0 == name || $0.hasPrefix(name + ".") && !$0.hasSuffix(".map") && !$0.hasSuffix(".atlas")
+ }
+ for file in files {
+ let handle = try FileHandle(forReadingFrom: folder.appending(path: file))
+ defer { try? handle.close() }
+ let header = try handle.read(upToCount: 24) ?? Data()
+ let mappings = Int(header.number(UInt32.self, at: 16)), count = Int(header.number(UInt32.self, at: 20))
+ try handle.seek(toOffset: 0)
+ let table = try handle.read(upToCount: mappings + count * 32) ?? Data()
+ for index in 0..<count {
+ let mapping = mappings + index * 32
+ let start = table.number(UInt64.self, at: mapping), length = table.number(UInt64.self, at: mapping + 8)
+ guard start <= address, address + UInt64(size) <= start + length else { continue }
+ try handle.seek(toOffset: table.number(UInt64.self, at: mapping + 16) + address - start)
+ return try handle.read(upToCount: Int(size)) ?? Data()
+ }
+ }
+ return Data()
+ }
+}
+
+private extension Data {
+ func number<Number: FixedWidthInteger>(_: Number.Type, at offset: Int) -> Number {
+ Number(littleEndian: withUnsafeBytes { $0.loadUnaligned(fromByteOffset: offset, as: Number.self) })
+ }
+
+ func cString(at offset: Int) -> String {
+ String(decoding: self[offset...].prefix { $0 != 0 }, as: UTF8.self)
+ }
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SystemCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SystemCachesTests.swift
index f3cfeea4..0ea561bd 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SystemCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SystemCachesTests.swift
@@ -3,20 +3,6 @@ import Foundation
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 everyLogIsNamedByThePartOfTheSealedSystemThatWritesIt() throws {
- for (name, source) in SystemLogs.named {
- let bytes = try Data(contentsOf: URL(filePath: source))
- #expect(bytes.range(of: Data("/Library/Logs/\(name)".utf8)) != nil, "\(name): \(source)")
- }
- }
-
@Test func knowsApplesCachesByTheirNameOrTheSystemsOwn() {
#expect(SystemCaches.isMacOSs("com.apple.Spotlight"))
#expect(SystemCaches.isMacOSs("CloudKit"))
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SystemFoldersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SystemFoldersTests.swift
new file mode 100644
index 00000000..c7c3e214
--- /dev/null
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SystemFoldersTests.swift
@@ -0,0 +1,32 @@
+import Foundation
+@testable import PeelCore
+import Testing
+
+struct SystemFoldersTests {
+ @Test func everyNameIsProvedByTheSealedSystem() throws {
+ let lists = [
+ SystemFolders.applicationSupport, SystemFolders.caches, SystemFolders.logs, SystemFolders.preferences,
+ ]
+ for (name, proof) in lists.joined() {
+ switch proof {
+ case .part(let path):
+ let part = URL(filePath: path).deletingPathExtension().lastPathComponent
+ let stem = URL(filePath: name).deletingPathExtension().lastPathComponent
+ #expect(FileManager.default.fileExists(atPath: path), "\(name): \(path)")
+ #expect(part == stem || part.hasSuffix("." + stem), "\(name): \(path)")
+ case .file(let path, let text):
+ let bytes = try Data(contentsOf: URL(filePath: path), options: .alwaysMapped)
+ #expect(bytes.range(of: Data(text.utf8)) != nil, "\(name): \(path)")
+ case .image(let path, let text):
+ #expect(try SharedCache.image(path, holds: text), "\(name): \(path)")
+ }
+ }
+ }
+
+ @Test func aProcessKeepsItsCachesHTTPStorageAndTemporaryItemsUnderOneName() {
+ #expect(SystemFolders.keeps("familycircled", in: .caches))
+ #expect(SystemFolders.keeps("familycircled", in: .httpStorages))
+ #expect(SystemFolders.keeps("familycircled", in: .temporaryItems))
+ #expect(!SystemFolders.keeps("familycircled", in: .library))
+ }
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SystemSupportFoldersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SystemSupportFoldersTests.swift
deleted file mode 100644
index 64eec896..00000000
--- a/Packages/PeelCore/Tests/PeelCoreTests/SystemSupportFoldersTests.swift
+++ /dev/null
@@ -1,12 +0,0 @@
-import Foundation
-@testable import PeelCore
-import Testing
-
-struct SystemSupportFoldersTests {
- @Test func everyNameIsCarriedByAPartOfTheSealedSystem() {
- for (name, source) in SystemSupportFolders.named {
- #expect(FileManager.default.fileExists(atPath: source), "\(name): \(source)")
- #expect(URL(filePath: source).deletingPathExtension().lastPathComponent == name, "\(name): \(source)")
- }
- }
-}
diff --git a/SAFETY.md b/SAFETY.md
index 3288c5af..75f3717a 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -326,6 +326,11 @@ Only matches Peel is `certain` or `likely` about, and only when nothing else ins
- **What macOS installed stays macOS's.** Something one of Apple's own installer packages put on the Mac, as its
receipt shows, is never listed with an app, whatever it is named, nor among what an uninstall leaves for an
administrator, such as a folder Xcode installed that is named for Chrome.
+- **What macOS keeps under a plain name stays macOS's.** macOS's own services keep some folders and files in your
+ Library and the Mac's under plain names, such as `Application Support/Knowledge`, `Caches/GeoServices`,
+ `Logs/Assistant`, or `/Library/Preferences/Logging`. An app called by the same name never takes one, and Orphaned
+ Files never lists one once such an app is gone. Peel knows each from macOS itself: a part of the system called by
+ that name, or one that names the path.
- **An empty folder of the app's maker goes too.** A folder in your Library or the Mac's named for the app or its
maker, such as `Application Support/<Maker>`, that an uninstall leaves empty goes to the Trash with it, through the
helper when its files went that way; one with anything left inside, a hidden file included, one with another name,