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
Put a gone app's team container with the rest of its files
Țugui Dragoș72ceeaa11e36
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swiftindex 34741755..628c1fe1 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift@@ -31,6 +31,10 @@ struct AppOwnership: Sendable {return false}+ func isAGoneApp(_ identifier: String) -> Bool {+ goneApps.contains(identifier.lowercased())+ }+/// 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, 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 isdiff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swiftindex 0147d534..44daffc0 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift@@ -463,7 +463,8 @@ public struct OrphanScanner: Sendable {static func orphanIdentifier(forKey key: String,kind: SearchLocation.Kind,- isDeclared: (String) -> Bool = { _ in false }+ isDeclared: (String) -> Bool = { _ in false },+ isAGoneApp: (String) -> Bool = { _ in false }) -> String? {var identifier = keyif kind == .groupContainers || kind == .applicationScripts, identifier.hasPrefix("group.") {@@ -476,8 +477,9 @@ public struct OrphanScanner: Sendable {if Identifier.isReverseDNS(identifier) {return identifier}- if kind == .groupContainers, Identifier.teamScoped(identifier) != nil {- return identifier+ if kind == .groupContainers, let remainder = Identifier.teamScoped(identifier)?.remainder {+ let app = remainder.hasPrefix("group.") ? String(remainder.dropFirst("group.".count)) : remainder+ return isAGoneApp(app) ? app : identifier}if Identifier.isValid(identifier), isDeclared(identifier) {return identifier@@ -546,8 +548,9 @@ 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, isDeclared: ownership.isDeclared)- else { return false }+ guard let identifier = orphanIdentifier(+ forKey: key, kind: kind, isDeclared: ownership.isDeclared, isAGoneApp: ownership.isAGoneApp+ ) else { return false }return ownership.isClaimed(fileName: name, kind: kind, identifier: identifier)}}@@ -618,10 +621,13 @@ public struct OrphanScanner: Sendable {!isSensitive(fileName: name),let identifier = (DeclaredIdentifier.nameSaysNothing(of: url, kind: kind)? nil : orphanIdentifier(- forKey: LeftoverMatcher.key(from: name, kind: kind), kind: kind, isDeclared: ownership.isDeclared+ forKey: LeftoverMatcher.key(from: name, kind: kind), kind: kind, isDeclared: ownership.isDeclared,+ isAGoneApp: ownership.isAGoneApp))?? DeclaredIdentifier.of(url, kind: kind).flatMap({- orphanIdentifier(forKey: $0, kind: kind, isDeclared: ownership.isDeclared)+ orphanIdentifier(+ forKey: $0, kind: kind, isDeclared: ownership.isDeclared, isAGoneApp: ownership.isAGoneApp+ )}),goneApps.map({ cameWithAnAppThatLeft(identifier, goneApps: $0) }) ?? true,!ownership.isClaimed(fileName: name, kind: kind, identifier: identifier),diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swiftindex 88eb476f..aed224e4 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift@@ -113,6 +113,44 @@ struct OrphanScannerTests {#expect(stillOrphaned.isEmpty)}+ @Test(arguments: ["ABCDE12345.md.example", "ABCDE12345.group.md.example"])+ func aTeamContainerOfATwoPartAppJoinsItsGroup(container: String) async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Group Containers/\(container)/data")+ try directory.file("home/Library/Preferences/md.example.plist")+ 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 scan = await scanner(in: directory).scan(installedApps: [], remembered: [gone])+ #expect(scan.groups.map(\.identifier) == ["md.example"])+ #expect(scan.groups.first?.items.count == 2)+ #expect(scan.groups.first?.rememberedApp?.bundleIdentifier == "md.example")++ let given = await scanner(in: directory).scan(+ installedApps: installed, remembered: [gone], owners: ["md.example": "com.installed.app"]+ )+ #expect(given.groups.isEmpty)++ let known = await scanner(in: directory, registered: ["md.example"]).scan(installedApps: [], remembered: [gone])+ #expect(known.groups.isEmpty)+ }++ @Test func aTeamContainerNamesAGoneAppOnly() {+ let gone = { (name: String) in name == "md.example" }+ #expect(+ OrphanScanner.orphanIdentifier(forKey: "ABCDE12345.md.example", kind: .groupContainers, isAGoneApp: gone)+ == "md.example"+ )+ #expect(+ OrphanScanner.orphanIdentifier(forKey: "ABCDE12345.md.installed", kind: .groupContainers, isAGoneApp: gone)+ == "ABCDE12345.md.installed"+ )+ }+@Test func aTwoPartIdentifierNoAppDeclaredIsNeverAskedAboutAsAPrefix() {let asked = Mutex<[String]>([])let ownership = AppOwnership(installedApps: [], goneApps: ["com.example.gone"]) { identifier in