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
List what a gone app named with its own identifier, whatever its shape
Țugui Dragoș22389acdfa99
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swiftindex 1a096481..62d89e1b 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift@@ -4,6 +4,8 @@ struct AppOwnership: Sendable {private let profiles: [LeftoverMatcher.Profile]private let goneApps: [String]private let isRegisteredApp: @Sendable (String) -> Bool+ /// The identifiers the installed apps and the gone ones declared, lowercased.+ private let declared: Set<String>/// `goneApps` are the identifiers of the apps Peel saw installed that are gone.init(@@ -14,6 +16,19 @@ struct AppOwnership: Sendable {profiles = installedApps.map(LeftoverMatcher.Profile.init)self.goneApps = goneApps.map { $0.lowercased() }self.isRegisteredApp = isRegisteredApp+ declared = Set(installedApps.compactMap { $0.bundleIdentifier?.lowercased() } + self.goneApps)+ }++ /// Whether `name` is an identifier an app declared, or one with three parts or more followed by a dot, as+ /// `AppMemory.app(for:in:)` reads it: then it names that app's files whatever its shape.+ func isDeclared(_ name: String) -> Bool {+ var components = name.lowercased().split(separator: ".", omittingEmptySubsequences: false)+ if declared.contains(components.joined(separator: ".")) { return true }+ while components.count > 3 {+ components.removeLast()+ if declared.contains(components.joined(separator: ".")) { return true }+ }+ return false}/// Returns whether an installed app has any claim on the item, even a weak one, or macOS knows an app by thediff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swiftindex b043210e..52f0b734 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift@@ -457,7 +457,11 @@ public struct OrphanScanner: Sendable {return ["steam", "steamlibrary", "epic games", "epicgameslauncher", "battle.net"].contains { name == $0 || name.hasPrefix($0 + ".") }}- static func orphanIdentifier(forKey key: String, kind: SearchLocation.Kind) -> String? {+ static func orphanIdentifier(+ forKey key: String,+ kind: SearchLocation.Kind,+ isDeclared: (String) -> Bool = { _ in false }+ ) -> String? {var identifier = keyif kind == .groupContainers || kind == .applicationScripts, identifier.hasPrefix("group.") {identifier.removeFirst("group.".count)@@ -472,6 +476,9 @@ public struct OrphanScanner: Sendable {if kind == .groupContainers, Identifier.teamScoped(identifier) != nil {return identifier}+ if Identifier.isValid(identifier), isDeclared(identifier) {+ return identifier+ }return nil}@@ -536,7 +543,8 @@ public struct OrphanScanner: Sendable {guard let names = await SlowRead.names(in: url) else { return nil }return names.contains { name inlet key = LeftoverMatcher.key(from: name, kind: kind)- guard let identifier = orphanIdentifier(forKey: key, kind: kind) else { return false }+ guard let identifier = orphanIdentifier(forKey: key, kind: kind, isDeclared: ownership.isDeclared)+ else { return false }return ownership.isClaimed(fileName: name, kind: kind, identifier: identifier)}}@@ -606,8 +614,12 @@ public struct OrphanScanner: Sendable {guard!isSensitive(fileName: name),let identifier = (DeclaredIdentifier.nameSaysNothing(of: url, kind: kind)- ? nil : orphanIdentifier(forKey: LeftoverMatcher.key(from: name, kind: kind), kind: kind))- ?? DeclaredIdentifier.of(url, kind: kind).flatMap({ orphanIdentifier(forKey: $0, kind: kind) }),+ ? nil : orphanIdentifier(+ forKey: LeftoverMatcher.key(from: name, kind: kind), kind: kind, isDeclared: ownership.isDeclared+ ))+ ?? DeclaredIdentifier.of(url, kind: kind).flatMap({+ orphanIdentifier(forKey: $0, kind: kind, isDeclared: ownership.isDeclared)+ }),goneApps.map({ cameWithAnAppThatLeft(identifier, goneApps: $0) }) ?? true,!ownership.isClaimed(fileName: name, kind: kind, identifier: identifier),!jobs.ownsItem(named: identifier),diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swiftindex 32cd3f45..09a4f305 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift@@ -748,6 +748,22 @@ struct OrphanScannerTests {#expect(given.groups.isEmpty)}+ @Test func listsWhatAGoneAppNamedWithAnIdentifierOfAnyShape() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Preferences/example.notes.plist")+ try directory.file("home/Library/Caches/exampleco.browser.app/cache.db")+ try directory.file("home/Library/Caches/example.other/cache.db")+ let gone = [("example.notes", "Notes Example"), ("exampleco.browser.app", "Browser Example")].map {+ RememberedApp(+ bundleIdentifier: $0.0, name: $0.1, teamIdentifier: nil, lastSeen: .now, lastPath: "/Applications/\($0.1).app"+ )+ }++ let scan = await scanner(in: directory).scan(installedApps: installed, remembered: gone)++ #expect(Set(scan.groups.map(\.identifier)) == ["example.notes", "exampleco.browser.app"])+ }+@Test func remembersWhichAppAGroupBelongsToUntilToldOtherwise() throws {let directory = try TemporaryDirectory()let owners = OrphanOwners(url: directory.url.appending(path: "orphan-owners.json"))