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
Ask macOS about a gone app's own identifier whatever its shape
Țugui Dragoș7408a2807d1e
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swiftindex 62d89e1b..34741755 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift@@ -32,8 +32,9 @@ struct AppOwnership: Sendable {}/// Returns whether an installed app has any claim on the item, even a weak one, or macOS knows an app by the- /// item's identifier or by a prefix of it with at least three components. The apps are asked about the- /// identifier as well as the name, since a plug-in is named for what it does and a container can be a UUID.+ /// item's identifier, by a prefix of it with at least three components, or by the identifier of the gone app it+ /// belongs to, whatever its shape. The apps are asked about the identifier as well as the name, since a plug-in is+ /// named for what it does and a container can be a UUID.func isClaimed(fileName: String, kind: SearchLocation.Kind, identifier: String) -> Bool {var candidates = [LeftoverMatcher.Candidate(LeftoverMatcher.key(from: fileName, kind: kind))]if candidates[0].key != identifier.lowercased() {@@ -59,7 +60,7 @@ struct AppOwnership: Sendable {// app Launch Services knows, is no owner of the web app's files.var components = OrphanScanner.groupingKey(for: identifier).split(separator: ".")let shortest = SafariWebApp.isIdentifier(identifier)- ? components.count : max(3, gone.map { $0.split(separator: ".").count } ?? 3)+ ? components.count : gone.map { $0.split(separator: ".").count } ?? 3while components.count >= shortest {if isRegisteredApp(components.joined(separator: ".")) {return truediff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swiftindex 7f9f1d08..88eb476f 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift@@ -89,6 +89,43 @@ struct OrphanScannerTests {#expect(!ownership.isClaimed(fileName: "ABCDE12345.org.other.thing", kind: .groupContainers, identifier: "ABCDE12345.org.other.thing"))#expect(!asked.withLock { $0 }.contains { $0.hasPrefix("ABCDE12345") || $0.hasPrefix("group.") })}+ @Test func aTwoPartAppMacOSKnowsElsewhereKeepsItsFiles() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Preferences/md.example.plist")+ try directory.file("home/Library/Caches/md.example.helper/data")+ let gone = RememberedApp(+ bundleIdentifier: "md.example", name: "Example", teamIdentifier: nil,+ lastSeen: .now.addingTimeInterval(-30 * 86_400),+ lastPath: "/Applications/Example.app",+ goneSince: .now.addingTimeInterval(-30 * 86_400)+ )++ let nobodyKnowsIt = await scanner(in: directory).scan(installedApps: [], remembered: [gone])+ #expect(nobodyKnowsIt.groups.map(\.identifier) == ["md.example"])+ #expect(nobodyKnowsIt.groups.flatMap(\.items).count == 2)++ let known = scanner(in: directory, registered: ["md.example"])+ let scan = await known.scan(installedApps: [], remembered: [gone])+ #expect(scan.groups.isEmpty)+ let stillOrphaned = await known.stillOrphaned(+ nobodyKnowsIt.groups.flatMap(\.items), installedApps: [], remembered: [gone]+ )+ #expect(stillOrphaned.isEmpty)+ }++ @Test func aTwoPartIdentifierNoAppDeclaredIsNeverAskedAboutAsAPrefix() {+ let asked = Mutex<[String]>([])+ let ownership = AppOwnership(installedApps: [], goneApps: ["com.example.gone"]) { identifier in+ asked.withLock { $0.append(identifier) }+ return false+ }++ #expect(!ownership.isClaimed(+ fileName: "com.example.other.plist", kind: .preferences, identifier: "com.example.other"+ ))+ #expect(asked.withLock { $0 } == ["com.example.other"])+ }+private let installed = [InstalledApp(url: URL(filePath: "/Applications/Installed.app"), bundleIdentifier: "com.installed.app", name: "Installed"),InstalledApp(url: URL(filePath: "/Applications/Word.app"), bundleIdentifier: "com.microsoft.Word", name: "Microsoft Word", teamIdentifier: "UBF8T346G9"),