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.

Count a running helper of a two-part app as that app

Țugui Dragoșdb7db8f02047
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift
index 8a9d5602..d0088e9a 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift
@@ -69,7 +69,8 @@ public struct OrphanConfidence: Sendable, Hashable {
running: Set<String> = [],
now: Date = .now
) -> OrphanConfidence {
- if running.contains(where: { isOneApp($0.lowercased(), group.identifier.lowercased()) }) {
+ let declared = group.rememberedApp?.bundleIdentifier.lowercased()
+ if running.contains(where: { isOneApp($0.lowercased(), group.identifier.lowercased(), declared: declared) }) {
return OrphanConfidence(level: .unsure, reasons: [.running])
}
if group.items.contains(where: { $0.heldBack == .loadedByOtherApps }) {
@@ -125,13 +126,13 @@ public struct OrphanConfidence: Sendable, Hashable {
}
/// Whether two identifiers belong to one app. A helper runs under its app's identifier or a longer one. A
- /// prefix counts only with three components or more, since two name a maker, not an app. A Safari web app's
- /// identifier begins with Safari's, and is still an app of its own.
- static func isOneApp(_ one: String, _ other: String) -> Bool {
+ /// prefix counts only with three components or more, since two name a maker, not an app, unless it is what the
+ /// app declared. A Safari web app's identifier begins with Safari's, and is still an app of its own.
+ static func isOneApp(_ one: String, _ other: String, declared: String? = nil) -> Bool {
if one == other { return true }
guard !SafariWebApp.isIdentifier(one), !SafariWebApp.isIdentifier(other) else { return false }
let (short, long) = one.count < other.count ? (one, other) : (other, one)
- return Identifier.componentCount(of: short) >= 3 && long.hasPrefix(short + ".")
+ return (Identifier.componentCount(of: short) >= 3 || short == declared) && long.hasPrefix(short + ".")
}
/// The group's last write, or nil when an item was not measured in time: what is inside it was not read.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift
index 80cabb6f..287d1c0c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift
@@ -97,6 +97,20 @@ struct OrphanConfidenceTests {
#expect(judged.reasons == [.sameMakerStillInstalled])
}
+ @Test func aHelperOfATwoPartAppRunningMakesItsGroupUnsure() {
+ let gone = RememberedApp(
+ bundleIdentifier: "md.example",
+ name: "Example",
+ teamIdentifier: nil,
+ lastSeen: now.addingTimeInterval(-40 * 24 * 60 * 60),
+ lastPath: "/Applications/Example.app"
+ )
+ let itsOwn = group(identifier: "md.example", written: 400 * 24 * 60 * 60, remembered: gone)
+ #expect(OrphanConfidence.judge(itsOwn, running: ["md.example.helper"], now: now).reasons == [.running])
+ let nobodysPrefix = group(identifier: "md.example", written: 400 * 24 * 60 * 60)
+ #expect(OrphanConfidence.judge(nobodysPrefix, running: ["md.example.helper"], now: now).level == .certain)
+ }
+
@Test("What is running is matched the way an app is: a helper runs under its app's identifier and a longer one")
func aRunningHelperOrItsAppBothCount() {
let old = group(identifier: "com.example.app", written: 400 * 24 * 60 * 60)