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.

Leave a folder named like the app to another app whose name holds it

Țugui Dragoș9d186d37f137
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index bec9ccb6..63def595 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -84,8 +84,9 @@ the Homebrew page's uninstall and cleanups are Homebrew's own.
by the program it runs, since anyone can name its file: a job that runs a program inside the app is the
app's, and one that runs a program inside another installed app is that app's. The answer is a
`LeftoverMatch`: a confidence (`certain`, `likely`, or `possible`), the reason, the other installed apps that
- claim the file too (with the apps of the same maker that macOS knows outside the Applications folders, and the
- apps Peel saw installed before, whose identifiers stay theirs once they are gone), the
+ claim the file too (with the apps of the same maker that macOS knows outside the Applications folders, the
+ apps Peel saw installed before, whose identifiers stay theirs once they are gone, and, for a file only the app's
+ name claims, another maker's app whose name holds that name as whole words), the
other copies of the app that use it (any macOS knows, wherever they are, named by their place), and, when Peel
holds it back, why (`HoldBack`).
3. **Measure.** `FileSize` walks each folder on a thread of its own, with a time budget. A size is what moving
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
index 7925ba19..bcfa9b23 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
@@ -115,6 +115,9 @@ struct LeftoverMatcher: Sendable {
// A job belongs to the app whose program it runs, so another app's program outranks any name.
let program = url.flatMap { Self.program(ofJobAt: $0, kind: kind) }
.flatMap { PathComponents.isPath($0, atOrInside: bundlePath) ? nil : $0 }
+ let isInItsOwnFolder = url.map {
+ namesTheAppOrItsMaker(folder: $0.deletingLastPathComponent().lastPathComponent)
+ } ?? false
for other in others where !goesWithTheItem(other) {
let runsItsProgram = program.map { PathComponents.isPath($0, atOrInside: other.path) } ?? false
let rival = runsItsProgram
@@ -123,6 +126,9 @@ struct LeftoverMatcher: Sendable {
// Siblings from the same maker, like Firefox Nightly beside Firefox, use the same files.
if target.isSibling(of: other), other.sharesName(with: candidate) {
share(with: other)
+ } else if evidence.family == .name, !isInItsOwnFolder, other.holdsAsWholeWords(candidate) {
+ // Another maker's app can keep a folder named by a word of its name, as Epic Games Launcher does.
+ share(with: other)
}
continue
}
@@ -269,6 +275,8 @@ extension LeftoverMatcher {
let withoutVersion: String?
let isApple: Bool
+ var isLongEnoughToShare: Bool { normalized.count >= 4 }
+
init(_ key: String) {
self.key = key.lowercased()
normalized = Naming.normalized(key)
@@ -358,6 +366,9 @@ extension LeftoverMatcher {
let vendorPrefix: String?
let names: [String]
let normalizedNames: 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>
let ownFolderNames: Set<String>
let isApplesOwn: Bool
let isASafariWebApp: Bool
@@ -384,6 +395,10 @@ extension LeftoverMatcher {
vendorPrefix = vendor.map { $0 + "." }
names = app.matchingNames.filter(Naming.isSignificant).map { $0.lowercased() }
normalizedNames = Set(names.map(Naming.normalized))
+ 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() } }
+ })
ownFolderNames = app.ownFolderNames
isApplesOwn = app.isSystemProtected || teamPrefix == Self.appleTeam
isASafariWebApp = app.isASafariWebApp
@@ -406,10 +421,14 @@ extension LeftoverMatcher {
/// True when one of this app's names begins with the candidate, or the candidate begins with it, like
/// "Firefox Nightly" and "Firefox".
func sharesName(with candidate: Candidate) -> Bool {
- guard candidate.normalized.count >= 4 else { return false }
+ guard candidate.isLongEnoughToShare else { return false }
return normalizedNames.contains { $0.hasPrefix(candidate.normalized) || candidate.normalized.hasPrefix($0) }
}
+ func holdsAsWholeWords(_ candidate: Candidate) -> Bool {
+ candidate.isLongEnoughToShare && wordRuns.contains(candidate.normalized)
+ }
+
/// An identifier without an identifier's shape counts as a name, under the names' rule: one too short or too
/// common for a name, such as a job labelled `updater`, claims nothing.
private func unproven(_ reason: MatchReason, _ candidate: Candidate) -> Evidence? {
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift
index aed5a0f4..cc479d72 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/AppOwnership.swift
@@ -54,6 +54,13 @@ struct AppOwnership: Sendable {
return false
}
+ /// Whether an installed app's name holds the item's name as whole words, as Epic Games Launcher holds Epic: what
+ /// only its name ties to a gone app may be that app's.
+ func anInstalledAppsNameHolds(fileName: String, kind: SearchLocation.Kind) -> Bool {
+ let candidate = LeftoverMatcher.Candidate(LeftoverMatcher.key(from: fileName, kind: kind))
+ return profiles.contains { $0.holdsAsWholeWords(candidate) }
+ }
+
/// The longest identifier of a gone app that `identifier` is, or begins with before a dot.
private func goneApp(owning identifier: String) -> String? {
let key = OrphanScanner.groupingKey(for: identifier).lowercased()
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
index 33802ab0..501ee39e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
@@ -605,7 +605,8 @@ public struct OrphanScanner: Sendable {
guard
namedPlaces.contains(kind), !isSensitive(fileName: name),
let app = goneNames[name.lowercased()],
- !ownership.isClaimed(fileName: name, kind: kind, identifier: app)
+ !ownership.isClaimed(fileName: name, kind: kind, identifier: app),
+ !ownership.anInstalledAppsNameHolds(fileName: name, kind: kind)
else { return nil }
return await holdsFilesOfAnInstalledApp(url, kind: kind, ownership: ownership) ? nil : app
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
index f35dce74..7a082739 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
@@ -300,7 +300,7 @@ struct LeftoverMatcherTests {
#expect(match("maccatalyst.org.other.reader", in: .containers, for: notes) == nil)
let writer = app("maccatalyst.org.alpha.writer", name: "Writer")
- let writerPro = app("maccatalyst.org.beta.writerpro", name: "Writer Pro")
+ let writerPro = app("maccatalyst.org.beta.writerpro", name: "WriterPro")
let folder = try #require(match("Writer", in: .applicationSupport, for: writer, with: [writerPro]))
#expect(folder.sharedWith.isEmpty, "another maker's app took a share")
}
@@ -348,6 +348,38 @@ struct LeftoverMatcherTests {
#expect(mail?.isShared == false)
}
+ @Test func aNameIsSharedWithAnotherMakersAppThatHoldsItAsWholeWords() throws {
+ let atlas = app("org.example.atlas", name: "Atlas", team: "AAAAAAAAAA")
+ let launcher = app("net.other.launcher", name: "Atlas Games Launcher", team: "BBBBBBBBBB")
+ let viewer = app("net.third.viewer", name: "Harbor Atlas", team: "CCCCCCCCCC")
+ let book = app("net.fourth.book", name: "Atlasbook", team: "DDDDDDDDDD")
+ let agent = InstalledApp(
+ url: URL(filePath: "/System/Library/CoreServices/Harbor Atlas Agent.app"),
+ bundleIdentifier: "net.fifth.agent",
+ name: "Harbor Atlas Agent",
+ isSystemProtected: true
+ )
+
+ let first = try #require(match("Atlas", in: .applicationSupport, for: atlas, with: [launcher]))
+ #expect(first.sharedWith == ["net.other.launcher"])
+ #expect(!first.isRecommended)
+ let last = try #require(match("Atlas", in: .caches, for: atlas, with: [viewer]))
+ #expect(last.sharedWith == ["net.third.viewer"])
+ let guess = try #require(match("Atlas Games", in: .applicationSupport, for: atlas, with: [launcher]))
+ #expect(guess.sharedWith == ["net.other.launcher"])
+
+ #expect(try #require(match("Atlas", in: .applicationSupport, for: atlas, with: [book])).isRecommended)
+ #expect(try #require(match("Atlas", in: .applicationSupport, for: atlas, with: [agent])).isRecommended)
+ let byIdentifier = try #require(match("org.example.atlas", in: .caches, for: atlas, with: [launcher, viewer]))
+ #expect(byIdentifier.isRecommended)
+ let inTheMakersFolder = LeftoverMatcher(app: atlas, installedApps: [atlas, launcher]) { _ in nil }.match(
+ fileName: "Atlas",
+ kind: .applicationSupport,
+ at: URL(filePath: "/Users/x/Library/Application Support/Example/Atlas")
+ )
+ #expect(try #require(inTheMakersFolder).isRecommended)
+ }
+
@Test func sharesOfficeGroupContainersBetweenApps() {
let word = app("com.microsoft.Word", name: "Microsoft Word", team: "UBF8T346G9", groups: ["UBF8T346G9.Office"])
let excel = app("com.microsoft.Excel", name: "Microsoft Excel", team: "UBF8T346G9", groups: ["UBF8T346G9.Office"])
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 4f9d667d..0441b484 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -688,6 +688,55 @@ struct OrphanScannerTests {
#expect(afterwards.isEmpty)
}
+ @Test func aFolderAnInstalledAppsNameHoldsAsWholeWordsIsNoOrphan() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/Library/Caches/Atlas/cache.db")
+ try directory.file("home/Library/Application Support/Atlas/settings.json")
+ let atlas = RememberedApp(
+ bundleIdentifier: "org.example.atlas", name: "Atlas", teamIdentifier: nil,
+ lastSeen: .now.addingTimeInterval(-90 * 24 * 60 * 60), lastPath: "/Applications/org.example.Atlas.app"
+ )
+ let launcher = InstalledApp(
+ url: URL(filePath: "/Applications/Atlas Games Launcher.app"), bundleIdentifier: "net.other.launcher",
+ name: "Atlas Games Launcher"
+ )
+ let scanner = scanner(in: directory)
+
+ let alone = await scanner.scan(installedApps: installed, remembered: [atlas]).groups
+ #expect(alone.map(\.identifier) == ["org.example.atlas"])
+ #expect(await scanner.scan(installedApps: installed + [launcher], remembered: [atlas]).groups.isEmpty)
+ let listed = try #require(alone.first).items
+ #expect(await scanner.stillOrphaned(listed, installedApps: installed + [launcher], remembered: [atlas]).isEmpty)
+ }
+
+ @Test func anotherAppsWordsLeaveWhatAGoneAppNamedByItsIdentifierListed() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/.atlas/argv.json")
+ let info = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <plist version="1.0"><dict><key>CFBundleIdentifier</key><string>org.example.atlas</string></dict></plist>
+ """
+ try directory.file(
+ "root/Library/Audio/Plug-Ins/Components/Atlas.component/Contents/Info.plist", contents: Data(info.utf8)
+ )
+ let atlas = RememberedApp(
+ bundleIdentifier: "org.example.atlas", name: "Atlas", teamIdentifier: nil, lastSeen: .now,
+ lastPath: "/Applications/Atlas.app",
+ productFolders: ProductFolders.vsCodeFolders(in: ["dataFolderName": ".atlas"])
+ )
+ let launcher = InstalledApp(
+ url: URL(filePath: "/Applications/Atlas Games Launcher.app"), bundleIdentifier: "net.other.launcher",
+ name: "Atlas Games Launcher"
+ )
+
+ let scanner = scanner(in: directory)
+
+ for apps in [installed, installed + [launcher]] {
+ let scan = await scanner.scan(installedApps: apps, remembered: [atlas])
+ #expect(Set(scan.groups.flatMap(\.items).map(\.url.lastPathComponent)) == [".atlas", "Atlas.component"])
+ }
+ }
+
/// The settings a Safari web app leaves are named by its own identifier, which begins with `com.apple.`. Once
/// the web app is gone they are orphans, while an installed web app keeps its own and Safari keeps Safari's.
/// Launch Services is this Mac's own, which knows Safari's web app template, `com.apple.Safari.WebApp`.
diff --git a/SAFETY.md b/SAFETY.md
index de22acc2..b411053a 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -276,6 +276,10 @@ Only matches Peel is `certain` or `likely` about, and only when nothing else ins
nor its maker, such as another app's, one of Apple's, or a command-line tool's, is shown and never selected, since a
folder of that name may be that program's own; so is something matched by name alone at the top of your home folder
or of a Library, or in a maker's folder there.
+- **A name another app carries is shared with it.** Something matched by the app's name alone is left unselected
+ while another installed app, whoever makes it, holds that name as whole words in its own, as Epic Games Launcher
+ holds Epic: a folder called Epic may be that app's. A word in the name of an app that comes with macOS counts for
+ nothing, and neither does another app's name for what sits in the app's or its maker's own folder.
- **Another app's data stays with it.** A folder that holds what another installed app keeps as its own, as the
Developer page names it, such as Xcode's folders in `~/Library/Developer`, is listed with that app named and can't
be selected: it goes with that app, never with this one.
@@ -416,7 +420,8 @@ The copy macOS installed of a system extension, in `/Library/SystemExtensions`,
only macOS removes it, and its note says how (on macOS 27, Delete Extension in System Settings for a network
extension; otherwise the app's move to the Trash in Finder), or that macOS removes it at the next restart. A file
named for a background job whose program is still there, such as the settings a remote access host keeps beside its
-job, is that job's and is never listed.
+job, is that job's and is never listed, and so is a folder named like a gone app while an installed app's name holds
+that name as whole words, as Epic Games Launcher holds Epic: it may be that app's.
On every list, Select All selects every row you can select, what Peel holds back included, and asks first,
counting what Peel doesn't recommend; Return answers Select Recommended. Each held back row still shows its reason