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
Peel reads a Mac Catalyst build's identifier after Xcode's prefix
Țugui Dragoș0432d219fab3
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swiftindex d7317d5e..9e315969 100644--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift@@ -25,15 +25,19 @@ public enum AppInspector {return names.contains(".Trash") || names.contains(".Trashes")}- /// The identifiers of the apps Spotlight has indexed whose identifier begins with `prefix`, wherever they are, such- /// as every app of one maker. Empty when Spotlight is off, has none, or does not answer within `budget`, and for a- /// prefix that is not made of an identifier's characters, since it goes into the query as it is.+ /// The identifiers of the apps Spotlight has indexed whose identifier begins with one of `prefixes`, wherever they+ /// are, such as every app of one maker. Empty when Spotlight is off, has none, or does not answer within `budget`,+ /// and when a prefix is not made of an identifier's characters, since each goes into the query as it is.static func indexedIdentifiers(- beginningWith prefix: String,+ beginningWith prefixes: [String],within budget: TimeInterval = spotlightBudget) async -> Set<String> {- guard !prefix.isEmpty, prefix.allSatisfy({ $0.isASCII && ($0.isLetter || $0.isNumber || "._-".contains($0)) }) else { return [] }- let text = "kMDItemContentTypeTree == \"com.apple.application-bundle\" && kMDItemCFBundleIdentifier == \"\(prefix)*\"c"+ let isAnIdentifiersStart = { (prefix: String) in+ !prefix.isEmpty && prefix.allSatisfy { $0.isASCII && ($0.isLetter || $0.isNumber || "._-".contains($0)) }+ }+ guard !prefixes.isEmpty, prefixes.allSatisfy(isAnIdentifiersStart) else { return [] }+ let identifiers = prefixes.map { "kMDItemCFBundleIdentifier == \"\($0)*\"c" }.joined(separator: " || ")+ let text = "kMDItemContentTypeTree == \"com.apple.application-bundle\" && (\(identifiers))"let found = await SlowRead.answer(within: budget) { _ -> Set<String> inguard let query = MDQueryCreate(kCFAllocatorDefault, text as CFString, nil, nil),MDQueryExecute(query, CFOptionFlags(kMDQuerySynchronous.rawValue))diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swiftindex bf5f551a..b9c85be7 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift@@ -312,7 +312,7 @@ extension LeftoverMatcher {if let teamPrefix, key.hasPrefix(teamPrefix) {return Evidence(.teamIdentifier, .possible, specificity: teamPrefix.count)}- if let vendorPrefix, key.hasPrefix(vendorPrefix) {+ if let vendorPrefix, Identifier.withoutCatalystPrefix(key).hasPrefix(vendorPrefix) {return Evidence(.vendorPrefix, .possible, specificity: vendorPrefix.count)}if let name = names.filter({ Naming.hasNamePrefix(key, name: $0) }).max(by: { $0.count < $1.count }) {diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swiftindex 119dbee3..ebf7d050 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift@@ -53,13 +53,11 @@ public struct LeftoverScanner: Sendable {/// The apps macOS knows, outside `known`, that may use `app`'s files: every other copy of it, such as an older one/// kept in Downloads or one on another disk, and the apps of the same maker, such as a Nightly build beside it./// Spotlight names the maker's apps and Launch Services says where each is installed, so a copy inside a backup- /// never counts. Apple's own apps are left to the list of what macOS ships, which Spotlight would name whole.+ /// never counts.private func appsElsewhere(like app: InstalledApp, besides known: [InstalledApp]) async -> [InstalledApp] {- var identifiers = [app.bundleIdentifier]- if !ProtectedData.isApplesName(app.bundleIdentifier), let vendor = Identifier.vendor(of: app.bundleIdentifier) {- let own = app.bundleIdentifier.lowercased()- identifiers += await AppInspector.indexedIdentifiers(beginningWith: vendor + ".").filter { $0.lowercased() != own }.sorted()- }+ let own = app.bundleIdentifier.lowercased()+ let makers = await AppInspector.indexedIdentifiers(beginningWith: Self.makersPrefixes(of: app.bundleIdentifier))+ let identifiers = [app.bundleIdentifier] + makers.filter { $0.lowercased() != own }.sorted()let wanted = Set(identifiers.map { $0.lowercased() })let bundle = PathPattern.comparablePath(of: PathPattern.canonical(app.url))let listed = Set(known.filter { wanted.contains($0.bundleIdentifier.lowercased()) }.map { PathPattern.comparablePath(of: PathPattern.canonical($0.url)) })@@ -70,6 +68,16 @@ public struct LeftoverScanner: Sendable {}.compactMap(AppInspector.inspect)}+ /// How the identifiers of the maker's apps begin, its Mac Catalyst builds' included. None for Apple's own apps:+ /// the list of what macOS ships holds them, and Spotlight would name them whole.+ static func makersPrefixes(of identifier: String) -> [String] {+ guard+ let vendor = Identifier.vendor(of: identifier),+ !ProtectedData.isApplesName(vendor + ".")+ else { return [] }+ return [vendor + ".", Identifier.catalystPrefix + vendor + "."]+ }+@concurrentfunc scan(_ app: InstalledApp, matcher: LeftoverMatcher) async -> LeftoverScan {let results = await withTaskGroup(of: (location: SearchLocation, result: LocationResult).self) { group indiff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swiftindex 445b68dd..1144baee 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift@@ -38,6 +38,10 @@ enum Naming {}enum Identifier {+ /// What Xcode puts in front of an iPad app's identifier when it builds the app for the Mac under an identifier+ /// of its own (`DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER`). The maker's name begins after it.+ static let catalystPrefix = "maccatalyst."+/// Leading pairs of components that name no single developer, so for these the vendor takes three components./// On a code host the third is the account, and under a country's registry (`uk.co`, which is `co.uk`/// reversed) it is the company. All of these are in the Public Suffix List.@@ -63,9 +67,10 @@ enum Identifier {}/// Whether a name found on disk reads as an app's identifier, "com.example.app": at least three components and a- /// lowercase top-level domain. Stricter than `isValid`, since a name nobody declared is only a guess.+ /// lowercase top-level domain after any `catalystPrefix`. Stricter than `isValid`, since a name nobody declared+ /// is only a guess.static func isReverseDNS(_ identifier: String) -> Bool {- let components = identifier.split(separator: ".", omittingEmptySubsequences: false)+ let components = withoutCatalystPrefix(identifier).split(separator: ".", omittingEmptySubsequences: false)guardcomponents.count >= 3,let domain = components.first,@@ -96,12 +101,16 @@ enum Identifier {}static func vendor(of identifier: String) -> String? {- let components = identifier.lowercased().split(separator: ".")+ let components = withoutCatalystPrefix(identifier.lowercased()).split(separator: ".")guard components.count >= 3 else { return nil }let domain = components.prefix(2).joined(separator: ".")guard sharedDomains.contains(domain) else { return domain }return components.count >= 4 ? components.prefix(3).joined(separator: ".") : nil}++ static func withoutCatalystPrefix(_ identifier: String) -> Substring {+ identifier.hasPrefix(catalystPrefix) ? identifier.dropFirst(catalystPrefix.count) : identifier[...]+ }}extension String {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swiftindex c285426a..6e02df34 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift@@ -36,27 +36,34 @@ struct AppInspectorTests {#expect(MachOHeader.architectures(inHeader: [0x00, 0x01]).isEmpty)}- /// Reads `/usr/bin/true`, the real binary the `universal` fixture above is modeled on.- /// Spotlight names the apps whose identifier begins with a maker's, wherever they are: every Mac has the- /// dictation input method in its input methods folder, outside the Applications folders. A Mac with Spotlight off- /// answers nothing, and the test waits for one that indexes. The other tests' scans ask Spotlight at the same- /// time, so this one is given longer than a scan waits.- @Test(.enabled("Spotlight indexes this Mac") { await !AppInspector.indexedIdentifiers(beginningWith: "com.apple.", within: 60).isEmpty })+ /// Spotlight names the apps whose identifier begins with any prefix asked, wherever they are: every Mac has the+ /// dictation input method in its input methods folder, outside the Applications folders, and TextEdit. A Mac with+ /// Spotlight off answers nothing, and the test waits for one that indexes. The other tests' scans ask Spotlight at+ /// the same time, so this one is given longer than a scan waits.+ @Test(.enabled("Spotlight indexes this Mac") {+ await !AppInspector.indexedIdentifiers(beginningWith: ["com.apple."], within: 60).isEmpty+ })func spotlightNamesTheAppsOfOneMaker() async {- let found = await AppInspector.indexedIdentifiers(beginningWith: "com.apple.inputmethod.", within: 60)+ let prefixes = ["com.apple.inputmethod.", "com.apple.TextEdit"]+ let found = await AppInspector.indexedIdentifiers(beginningWith: prefixes, within: 60)#expect(found.contains("com.apple.inputmethod.ironwood"))- #expect(found.allSatisfy { $0.lowercased().hasPrefix("com.apple.inputmethod.") })+ #expect(found.contains("com.apple.TextEdit"))+ let lowercased = prefixes.map { $0.lowercased() }+ #expect(found.allSatisfy { identifier in lowercased.contains { identifier.lowercased().hasPrefix($0) } })}/// A bundle writes its own identifier, and a maker's prefix taken from it goes into a Spotlight query. One that/// could change the query asks nothing.@Test func aPrefixThatCouldChangeTheQueryAsksNothing() async {for prefix in ["com.example\" || kMDItemFSName == \"*", "com.example *", "", "com.example.\\"] {- #expect(await AppInspector.indexedIdentifiers(beginningWith: prefix).isEmpty, "\(prefix)")+ #expect(await AppInspector.indexedIdentifiers(beginningWith: [prefix]).isEmpty, "\(prefix)")+ #expect(await AppInspector.indexedIdentifiers(beginningWith: ["com.apple.", prefix]).isEmpty, "\(prefix)")}+ #expect(await AppInspector.indexedIdentifiers(beginningWith: []).isEmpty)}+ /// Reads `/usr/bin/true`, the real binary the `universal` fixture above is modeled on.@Test func readsARealBinaryTheSameWay() {#expect(MachOHeader.architectures(ofExecutableAt: URL(filePath: "/usr/bin/true")).contains(.arm64))}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swiftindex 02f97be2..ebdce92d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift@@ -221,6 +221,21 @@ struct LeftoverMatcherTests {#expect(match("jp.co.other.Thing", in: .caches, for: canon) == nil)}+ @Test func aMacCatalystBuildIsItsMakersApp() throws {+ #expect(Identifier.vendor(of: "maccatalyst.org.example.notes") == "org.example")++ let notes = app("maccatalyst.org.example.notes", name: "Notes Probe")+ let mail = app("org.example.mail", name: "Mail Probe")+ #expect(match("org.example.mail.helper", in: .caches, for: notes)?.confidence == .possible)+ #expect(match("maccatalyst.org.example.notes", in: .containers, for: mail)?.confidence == .possible)+ #expect(match("maccatalyst.org.other.reader", in: .containers, for: notes) == nil)++ let writer = app("maccatalyst.org.alpha.writer", name: "Writer")+ let writerPro = app("maccatalyst.org.beta.writerpro", name: "Writer Pro")+ let folder = try #require(match("Writer", in: .applicationSupport, for: writer, with: [writerPro]))+ #expect(folder.sharedWith.isEmpty, "another maker's app took a share")+ }+@Test func appleItemsOnlyMatchExactIdentifiers() throws {let xcode = app("com.apple.dt.Xcode", name: "Xcode", team: "59GAB85EFG")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swiftindex 22947080..f941449e 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift@@ -111,6 +111,15 @@ struct LeftoverScannerTests {}}+ @Test func asksSpotlightForTheMakersAppsButNeverApples() {+ let makers = ["org.example.", "maccatalyst.org.example."]+ #expect(LeftoverScanner.makersPrefixes(of: "org.example.notes") == makers)+ #expect(LeftoverScanner.makersPrefixes(of: "maccatalyst.org.example.notes") == makers)+ #expect(LeftoverScanner.makersPrefixes(of: "com.apple.Safari").isEmpty)+ #expect(LeftoverScanner.makersPrefixes(of: "maccatalyst.com.apple.news").isEmpty)+ #expect(LeftoverScanner.makersPrefixes(of: "org.example").isEmpty)+ }+/// An app inside the home's Library or the Mac's is part of another app, such as an agent kept in its maker's/// support folder or a build, so it keeps no file of an app it resembles. macOS's own Library is not one of them.@Test func anAppInALibraryFolderIsPartOfAnotherApp() {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swiftindex 97802a4b..8e6ea60d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift@@ -403,10 +403,24 @@ struct OrphanScannerTests {("Spotify", .applicationSupport, nil),("com.example", .caches, nil),("Com.Example.App", .caches, nil),+ ("maccatalyst.org.example.notes", .containers, "maccatalyst.org.example.notes"),+ ("maccatalyst.org.example", .caches, nil),+ ("maccatalyst.com.apple.news", .containers, nil),] as [(String, SearchLocation.Kind, String?)])func identifiesAppShapedNames(key: String, kind: SearchLocation.Kind, expected: String?) {#expect(OrphanScanner.orphanIdentifier(forKey: key, kind: kind) == expected)}++ @Test func findsWhatAMacCatalystBuildLeft() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Containers/maccatalyst.org.example.notes/Data/Library/Caches/cache.db")+ try directory.file("home/Library/Preferences/maccatalyst.org.example.notes.plist")++ let scan = await scanner(in: directory).scan(installedApps: installed)++ #expect(scan.groups.map(\.identifier) == ["maccatalyst.org.example.notes"])+ #expect(scan.groups.first?.items.count == 2)+ }/// A crash reporter keeps a folder per app inside its own. The folder is named after the reporter, which/// nothing installed answers to, but what is inside belongs to an app that is still here.@Test func leavesAloneAFolderHoldingAnInstalledAppsFiles() async throws {