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.

Stop reading a tool's default identifier as one maker

Țugui Dragoș69977864e138
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift
index a718e655..3b0317b6 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift
@@ -63,13 +63,15 @@ enum 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.
+ /// Leading pairs of components that name no single developer, so for these the vendor takes three components:
+ /// an account on a code host, a company under a country's registry (each in the Public Suffix List), or the app
+ /// under what a tool writes when its maker sets none: `com.electron.<name>` from Electron's packagers, Qt's
+ /// `com.yourcompany.<name>`, and ToDesktop's and install4j's own (install4j's names a project).
private static let sharedDomains: Set<String> = [
"com.github", "io.github", "com.gitlab", "io.gitlab", "org.sourceforge", "net.sourceforge", "com.googlecode",
"uk.co", "uk.org", "uk.ac", "au.com", "au.net", "au.org", "jp.co", "jp.ne", "jp.or", "nz.co", "kr.co",
"za.co", "il.co", "in.co", "br.com", "cn.com", "tw.com", "hk.com", "sg.com", "mx.com", "ar.com", "tr.com",
+ "com.electron", "com.yourcompany", "com.todesktop", "com.install4j",
]
static func componentCount(of identifier: String) -> Int {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
index 78854e63..65d7c584 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
@@ -299,6 +299,22 @@ struct LeftoverMatcherTests {
#expect(match("jp.co.other.Thing", in: .caches, for: canon) == nil)
}
+ @Test func aToolsDefaultIdentifierNamesNoMaker() throws {
+ for prefix in ["com.electron", "com.yourcompany", "com.todesktop"] {
+ #expect(Identifier.vendor(of: "\(prefix).alpha") == nil, "\(prefix)")
+ #expect(Identifier.vendor(of: "\(prefix).alpha.helper") == "\(prefix).alpha", "\(prefix)")
+ }
+ #expect(Identifier.vendor(of: "com.install4j.1234-5678-9012-3456.10") == "com.install4j.1234-5678-9012-3456")
+
+ let alpha = app(
+ "com.electron.alpha", name: "Alpha", team: "AAAAAAAAAA", embedded: ["com.electron.alpha.helper"]
+ )
+ let beta = app("com.electron.beta", name: "Beta", team: "BBBBBBBBBB")
+ #expect(match("com.electron.beta", in: .caches, for: alpha) == nil)
+ #expect(match("com.electron.beta.plist", in: .preferences, for: alpha, with: [beta]) == nil)
+ #expect(try #require(match("com.electron.alpha.helper", in: .caches, for: alpha)).confidence == .certain)
+ }
+
@Test func aMacCatalystBuildIsItsMakersApp() throws {
#expect(Identifier.vendor(of: "maccatalyst.org.example.notes") == "org.example")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 0441b484..511a45c0 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -709,6 +709,18 @@ struct OrphanScannerTests {
#expect(await scanner.stillOrphaned(listed, installedApps: installed + [launcher], remembered: [atlas]).isEmpty)
}
+ @Test func anAppUnderAToolsDefaultIdentifierKeepsNoOtherAppsOrphanBack() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/Library/Caches/com.electron.gone/cache.db")
+ let alpha = InstalledApp(
+ url: URL(filePath: "/Applications/Alpha.app"), bundleIdentifier: "com.electron.alpha", name: "Alpha"
+ )
+
+ let scan = await scanner(in: directory).scan(installedApps: installed + [alpha])
+
+ #expect(scan.groups.map(\.identifier) == ["com.electron.gone"])
+ }
+
@Test func anotherAppsWordsLeaveWhatAGoneAppNamedByItsIdentifierListed() async throws {
let directory = try TemporaryDirectory()
try directory.file("home/.atlas/argv.json")