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.

Show for review a folder named like the app without its channel word

Țugui Dragoș46aa47b5b74c
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
index 8daf9271..dbee838b 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
@@ -95,7 +95,7 @@ struct LeftoverMatcher: Sendable {
// A name still hidden here is the system's own: `.GlobalPreferences.plist` is the global domain.
guard !key.hasPrefix(".") else { return nil }
let candidate = Candidate(key)
- guard let evidence = target.evidence(for: candidate) else { return nil }
+ guard let evidence = target.claim(for: candidate) else { return nil }
var sharedWith: Set<String> = []
var otherCopies: [URL] = []
@@ -369,6 +369,8 @@ extension LeftoverMatcher {
let vendorPrefix: String?
let names: [String]
let normalizedNames: Set<String>
+ /// The app's names without a release channel's word, normalized: `zed` for Zed Nightly.
+ let channelNames: Set<String>
/// Each run of whole words in the app's names, normalized: Epic Games Launcher holds `epic` and `epicgames`.
/// None for an app macOS ships, whose words say nothing: `Base` is not AirPort Base Station Agent's.
let wordRuns: Set<String>
@@ -401,6 +403,8 @@ extension LeftoverMatcher {
vendorPrefix = vendor.map { $0 + "." }
names = app.matchingNames.filter(Naming.isSignificant).map { $0.lowercased() }
normalizedNames = Set(names.map(Naming.normalized))
+ channelNames = Set(names.compactMap(Naming.withoutChannel).map(Naming.normalized))
+ .subtracting(normalizedNames)
wordRuns = app.isSystemProtected ? [] : Set(names.flatMap { name in
let words = name.split { !$0.isLetter && !$0.isNumber }.map(String.init)
return words.indices.flatMap { start in words.indices[start...].map { words[start...$0].joined() } }
@@ -441,6 +445,17 @@ extension LeftoverMatcher {
Naming.isSignificant(candidate.key) ? Evidence(unproven: reason, for: candidate) : nil
}
+ /// The app's own claim on the item: its evidence, or, with none, a name of its without the channel word,
+ /// which claims only for review, since the release the folder belongs to may be installed elsewhere.
+ func claim(for candidate: Candidate) -> Evidence? {
+ if let evidence = evidence(for: candidate) { return evidence }
+ guard !candidate.isApple,
+ channelNames.contains(candidate.normalized)
+ || candidate.withoutVersion.map(channelNames.contains) == true
+ else { return nil }
+ return Evidence(.name, .possible, specificity: candidate.normalized.count)
+ }
+
func evidence(for candidate: Candidate) -> Evidence? {
let key = candidate.key
// Everything an app says about itself (its identifier, what it embeds, the groups it claims)
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift
index 3b0317b6..00d4d646 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift
@@ -51,6 +51,22 @@ enum Naming {
return isSignificant(base) ? base : nil
}
+ /// The words a maker puts after an app's name for a release channel, which its folders carry no more than they
+ /// carry a version: Zed Nightly keeps its settings in `zed`.
+ static let channelWords: Set<String> = [
+ "alpha", "beta", "canary", "dev", "nightly", "preview", "insiders", "ptb", "rc",
+ ]
+
+ /// "Zed Nightly" → "Zed", "Xcode-beta" → "Xcode". Only the last word counts, and what is left has to name the
+ /// app.
+ static func withoutChannel(_ name: String) -> String? {
+ guard let separator = name.lastIndex(where: separators.contains) else { return nil }
+ guard channelWords.contains(normalized(String(name[name.index(after: separator)...]))) else { return nil }
+ var base = String(name[..<separator])
+ while let last = base.last, separators.contains(last) { base.removeLast() }
+ return isSignificant(base) ? base : nil
+ }
+
/// True when `key` starts with `name` followed by a separator. Expects both arguments lowercased.
static func hasNamePrefix(_ key: String, name: String) -> Bool {
guard key.count > name.count, key.hasPrefix(name) else { return false }
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift
index cc479d72..1a096481 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift
@@ -35,7 +35,7 @@ struct AppOwnership: Sendable {
}
}
if profiles.contains(where: { profile in
- candidates.contains { profile.evidence(for: $0).map(claims) ?? false }
+ candidates.contains { profile.claim(for: $0).map(claims) ?? false }
}) {
return true
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
index 59a9ee7d..097f5cc9 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
@@ -496,6 +496,33 @@ struct LeftoverMatcherTests {
#expect(Naming.withoutTrailingVersion("Numi") == nil)
}
+ /// "Harbor Nightly" keeps its channel in the app's name but not in its folders, which the stable release uses
+ /// too, so the folder is shown for review and never selected, and shared with the stable release while that one
+ /// is installed.
+ @Test func showsForReviewAFolderNamedLikeTheAppWithoutItsChannelWord() throws {
+ let nightly = app("org.example.harbor-nightly", name: "Harbor Nightly")
+ let harbor = app("org.example.harbor", name: "Harbor")
+
+ let alone = try #require(match("harbor", in: .hiddenHomeFiles, for: nightly))
+ #expect(alone.reason == .name && alone.confidence == .possible && !alone.isRecommended)
+ #expect(match("Harbor", in: .applicationSupport, for: nightly)?.confidence == .possible)
+ #expect(match("Harbor Nightly", in: .applicationSupport, for: nightly)?.confidence == .likely)
+ let beside = try #require(match("harbor", in: .hiddenHomeFiles, for: nightly, with: [harbor]))
+ #expect(beside.sharedWith == [harbor.reference] && !beside.isRecommended)
+ let stables = try #require(match("harbor", in: .hiddenHomeFiles, for: harbor, with: [nightly]))
+ #expect(stables.sharedWith == [nightly.reference] && !stables.isRecommended)
+ }
+
+ @Test func dropsOnlyAChannelWordThatEndsTheName() {
+ #expect(Naming.withoutChannel("Zed Nightly") == "Zed")
+ #expect(Naming.withoutChannel("Xcode-beta") == "Xcode")
+ #expect(Naming.withoutChannel("Discord PTB") == "Discord")
+ #expect(Naming.withoutChannel("Edge Dev") == "Edge")
+ #expect(Naming.withoutChannel("Microsoft Edge") == nil, "a product's name is no channel")
+ #expect(Naming.withoutChannel("Beta") == nil)
+ #expect(Naming.withoutChannel("Zed") == nil)
+ }
+
/// The matcher only reports evidence. `LeftoverScanner.heldBack` decides that `~/.jotter` is shown but never
/// selected, after `nested(in:)` has used the same evidence to decide whether to list the item at all. See
/// `aHiddenHomeEntryOnANameIsShownAndNeverSelected`.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 511a45c0..731927dd 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -64,6 +64,17 @@ struct OrphanScannerTests {
}
+ @Test func anInstalledReleaseChannelClaimsTheFoldersNamedForItsApp() {
+ let nightly = InstalledApp(
+ url: URL(filePath: "/Applications/Harbor Nightly.app"), bundleIdentifier: "org.example.harbor-nightly",
+ name: "Harbor Nightly"
+ )
+ let ownership = AppOwnership(installedApps: [nightly]) { _ in false }
+
+ #expect(ownership.isClaimed(fileName: "harbor", kind: .hiddenHomeFiles, identifier: "harbor"))
+ #expect(!ownership.isClaimed(fileName: "anchor", kind: .hiddenHomeFiles, identifier: "anchor"))
+ }
+
/// Launch Services is asked about apps outside the scanned folders. It knows an app by its bundle identifier,
/// never by a group container's name, which has a team or `group.` in front.
@Test func asksMacOSAboutTheAppBehindAGroupContainer() {