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
Find what a removed app left under its name, however it is written
Țugui Dragoșc0ab4b23d462
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex a3eaf270..4522a4e1 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -387,7 +387,9 @@ macOS asks the user to approve it once. It talks to the app over XPC.couldn't check, or about one this revision asks nobody about, is dropped, so the app is asked again at the nextround.- **Orphaned Files.** `OrphanScanner` lists what no installed app claims, under the app Peel saw go when it can- name it (`AppMemory`), and selects nothing for the person. An app macOS knows on another disk that claims something+ name it (`AppMemory`), and selects nothing for the person. Once every location is read, the identifiers it found+ teach their apps' names (`learnedNames`), which it looks for in the places an app keeps a folder under its name; a+ name, remembered or learned, is compared without case, spaces, or punctuation (`nameKey`). An app macOS knows on another disk that claims somethingis remembered too (`OrphanScan.appsOnOtherDisks`, `Disks`), so its files stay its own while that disk isn'tconnected, and a link into an app on such a disk is not one into an app that is gone.- **Intel Software.** `IntelInspector` judges by the code itself: what a bundle runs, or a file, is Intel only whendiff --git a/GUIDE.md b/GUIDE.mdindex bb18b739..8fb960a7 100644--- a/GUIDE.md+++ b/GUIDE.md@@ -109,8 +109,10 @@ Space shows what fills your disk, area by area, and what each area is.- **Orphaned Files:** files left behind by apps you already removed. Each group is tied to its app by the app'sidentifier, by a folder a code editor or a JetBrains IDE named for its data, by the name of an app Peel saw- installed and then saw go, or, for the copy macOS keeps of a system extension, by the app macOS's own record- names. An app on another disk keeps its files out of the list while that disk isn't connected, once Orphaned Files+ installed and then saw go, with or without its spaces and dashes and also at the top of a Library, by the name the+ app's own identifier gives it, such as `VirtualBuddy` for `codes.rambo.VirtualBuddy`, when that identifier stays in+ what the app left, or, for the copy macOS keeps of a system extension, by the app macOS's own record names. What+ only a name ties to an app is shown and never selected. An app on another disk keeps its files out of the list while that disk isn't connected, once Orphaned Fileshas looked with the disk connected. It also lists the files browsers keep to start a helper program that is gone.Nothing is selected for you. A system extension's copy can't be selected, since only macOS removes it, and its rowsays how. Peel doesn't list what only a guess could tie to an app, so look for it yourself: a folder named only fordiff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swiftindex 951b89c4..376eaa2f 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift@@ -95,8 +95,9 @@ public struct OrphanConfidence: Sendable, Hashable {reasons: [.installedForAnAppThatIsGone(name: name)])}- if let app = group.rememberedApp, group.items.allSatisfy({ $0.namedAfter != nil }) {- return OrphanConfidence(level: .unsure, reasons: [.onlyTheName(of: app.name)])+ if group.items.allSatisfy({ $0.namedAfter != nil }) {+ let name = group.rememberedApp?.name ?? group.identifier.split(separator: ".").last.map(String.init)+ return OrphanConfidence(level: .unsure, reasons: [.onlyTheName(of: name ?? group.identifier)])}let makerIsStillHere = group.rememberedApp?.teamIdentifier.map(installedTeams.contains) ?? false// A folder's own date changes when files are taken out of it, so the last write on a leftover is oftendiff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swiftindex 44daffc0..564396d3 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift@@ -97,7 +97,9 @@ public struct OrphanScanner: Sendable {)let goneNames = Dictionary(- gone.map { ($0.name.lowercased(), $0.bundleIdentifier) },+ gone.compactMap { app in+ Self.nameKey(of: app.name).map { ($0, app.bundleIdentifier) }+ },uniquingKeysWith: { first, _ in first })let goneFolders = GoneFolders(gone, installedApps: installedApps, home: environment.homeDirectory)@@ -141,6 +143,22 @@ public struct OrphanScanner: Sendable {}}+ // An identifier left behind names its app's own folders too, often in another location, so the names it+ // teaches are looked for once every location is read.+ let learned = Self.learnedNames(+ from: found, installedIdentifiers: (installedApps + systemApps).compactMap(\.bundleIdentifier),+ known: goneNames+ )+ for location in environment.locations where !learned.isEmpty && Self.learnedPlaces.contains(location.kind) {+ let named = await Self.named(+ in: location, names: learned, listed: seen, ownership: ownership,+ home: environment.homeDirectory.path(percentEncoded: false),+ root: environment.rootDirectory.path(percentEncoded: false), walk: walk+ )+ found += named.items.filter { seen.insert(PathPattern.comparablePath(of: $0.item.url)).inserted }+ unreadableLocations += named.unreadable+ }+let reach = HelperReach(environment: environment)let staged = PathPattern.comparablePath(of: environment.rootDirectory.appending(path: "Library/SystemExtensions"))let isStaged = { (item: OrphanItem) in@@ -438,7 +456,7 @@ public struct OrphanScanner: Sendable {await Self.goneApp(named: item.url,kind: item.kind,- goneNames: [item.url.lastPathComponent.lowercased(): app],+ goneNames: Self.nameKey(of: item.url.lastPathComponent).map { [$0: app] } ?? [:],ownership: ownership) == .listed(app)} else if case .listed = await Self.orphanIdentifier(@@ -655,11 +673,93 @@ public struct OrphanScanner: Sendable {}/// The places where an app keeps a folder under its own name, such as `Caches/Figma`, and nothing it keeps- /// there is the person's own work.+ /// there is the person's own work. At the top of a Library a name is a guess, as it is for an uninstall, so only+ /// the name of an app Peel saw counts there, and never for a folder every Library shares, such as Fonts.static let namedPlaces: Set<SearchLocation.Kind> = [- .caches, .logs, .savedApplicationState, .httpStorages, .webKit, .applicationSupport,+ .caches, .logs, .savedApplicationState, .httpStorages, .webKit, .applicationSupport, .library,]+ /// Where a name an identifier taught (`learnedNames`) is looked for.+ static let learnedPlaces = namedPlaces.subtracting([.library])++ /// The name an item bears for an app, compared without case, spaces, or punctuation, so `rancher-desktop` is+ /// Rancher Desktop's. Nil for a name too short or too generic to tell.+ static func nameKey(of fileName: String) -> String? {+ let key = Naming.folderName(fileName)+ return key.count >= 3 && !Naming.genericNames.contains(key) ? key : nil+ }++ /// The names the identifiers in `found` teach, each with its identifier: the third part of an app's identifier,+ /// which names the app (`VirtualBuddy` in `codes.rambo.VirtualBuddy`), while a fourth names a part of it. Never a+ /// plug-in's or a framework's, named for what it does, never a maker's name, and never a name two give.+ static func learnedNames(+ from found: [(identifier: String, item: OrphanItem)], installedIdentifiers: [String], known: [String: String]+ ) -> [String: String] {+ let identifiers = found.filter { !$0.item.kind.isLoadedCode && $0.item.namedAfter == nil }+ .map { groupingKey(for: $0.identifier) }+ let makers = Set((identifiers + installedIdentifiers).compactMap { identifier in+ Identifier.vendor(of: identifier)?.split(separator: ".").last.map { Naming.normalized(String($0)) }+ })+ var names: [String: String] = [:]+ var twice: Set<String> = []+ for identifier in identifiers {+ let parts = identifier.split(separator: ".")+ guard parts.count == 3, let key = nameKey(of: String(parts[2])), !makers.contains(key), known[key] == nil+ else { continue }+ if let other = names[key], other.lowercased() != identifier.lowercased() { twice.insert(key) }+ names[key] = names[key] ?? identifier+ }+ return names.filter { !twice.contains($0.key) }+ }++ /// What in `location` bears one of `names` and isn't listed yet, measured, each named after its identifier.+ private static func named(+ in location: SearchLocation,+ names: [String: String],+ listed: Set<String>,+ ownership: AppOwnership,+ home: String,+ root: String,+ walk: @escaping LeftoverScanner.Measure+ ) async -> (items: [(identifier: String, item: OrphanItem)], unreadable: [SearchLocation]) {+ let path = location.url.path(percentEncoded: false)+ guard let entries = try? FileManager.default.contentsOfDirectory(atPath: path) else { return ([], []) }+ let parent = ParentAccess(location.url)+ var candidates: [Candidate] = []+ var unreadable: [SearchLocation] = []+ for name in entries.sorted() where location.considers(fileName: name) && !Task.isCancelled {+ let url = location.url.appending(path: name)+ guard !listed.contains(PathPattern.comparablePath(of: url)), isAFileAFolderOrALink(url),+ !FileAccess.cannotBeRemoved(url), !ProtectedData.refuses(url.path(percentEncoded: false), home: home)+ else { continue }+ switch await goneApp(named: url, kind: location.kind, goneNames: names, ownership: ownership) {+ case .listed(let identifier):+ candidates.append(Candidate(url: url, identifier: identifier, namedAfter: identifier, parent: parent))+ case .notKnown: unreadable.append(SearchLocation(kind: location.kind, url: url))+ case .notListed: continue+ }+ }+ let walked = await candidates.map(\.url).concurrentMap(width: LeftoverScanner.concurrentMeasurements) {+ await walk($0)+ }+ let items = zip(candidates, walked).map { candidate, contents in+ (+ identifier: candidate.identifier,+ item: item(+ at: candidate.url, kind: location.kind, contents: contents, parent: candidate.parent, home: home,+ root: root, namedAfter: candidate.namedAfter+ )+ )+ }+ return (items, unreadable)+ }++ /// A folder every Library has and no one app owns, as the folders packages share name it.+ private static func isSharedLibraryFolder(_ name: String) -> Bool {+ let path = "/Library/" + name+ return PackageReceipts.sharedDirectories.contains(path) || PackageReceipts.sharedInTheHome.contains(path)+ }+/// The app that left whose name `url` bears, in one of `namedPlaces`, while no installed app claims that name.static func goneApp(named url: URL,@@ -670,7 +770,7 @@ public struct OrphanScanner: Sendable {let name = url.lastPathComponentguardnamedPlaces.contains(kind), !isSensitive(fileName: name), !SystemFolders.keeps(name, in: kind),- let app = goneNames[name.lowercased()],+ kind != .library || !isSharedLibraryFolder(name), let key = nameKey(of: name), let app = goneNames[key],!ownership.isClaimed(fileName: name, kind: kind, identifier: app),!ownership.anInstalledAppsNameHolds(fileName: name, kind: kind)else { return .notListed }diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swiftindex bb0fc73f..7c641f74 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift@@ -57,6 +57,21 @@ struct OrphanConfidenceTests {#expect(OrphanConfidence.judge(alone, now: now).reasons == [.loadedByOtherApps])}+ @Test func whatOnlyANameTiesToAnIdentifierLeftBehindIsUnsureWithoutMemory() {+ var item = OrphanItem(+ url: URL(filePath: "/Users/someone/Library/Application Support/Tidewater", directoryHint: .isDirectory),+ kind: .applicationSupport, size: 1_000, modificationDate: now.addingTimeInterval(-400 * 24 * 60 * 60),+ requiresPrivileges: false+ )+ item.namedAfter = "org.example.Tidewater"+ item.heldBack = .namedLikeTheApp+ let named = OrphanGroup(identifier: "org.example.Tidewater", items: [item])++ #expect(OrphanConfidence.judge(named, now: now) == OrphanConfidence(+ level: .unsure, reasons: [.onlyTheName(of: "Tidewater")]+ ))+ }+@Test("Something running under that identifier settles it, whatever else is true")func runningOutranksEverything() {let old = group(written: 400 * 24 * 60 * 60, remembered: left("Example"))diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swiftindex cf3a64b0..67a5314f 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift@@ -937,6 +937,77 @@ struct OrphanScannerTests {#expect(afterwards.isEmpty)}+ @Test func findsAGoneAppsNameWrittenAnotherWayAndAtTheTopOfTheLibrary() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Application Support/tide-pool/extensions/index.json")+ try directory.file("home/Library/Tide Pool/settings.json")+ try directory.file("home/.tidepool/config.yaml")+ try directory.file("home/Library/Fonts/Tide.ttf")+ let tidePool = RememberedApp(+ bundleIdentifier: "org.example.tidepool", name: "Tide Pool", teamIdentifier: nil,+ lastSeen: .now.addingTimeInterval(-90 * 24 * 60 * 60), lastPath: "/Applications/org.example.TidePool.app"+ )+ let fonts = RememberedApp(+ bundleIdentifier: "org.example.fonts", name: "Fonts", teamIdentifier: nil,+ lastSeen: .now.addingTimeInterval(-90 * 24 * 60 * 60), lastPath: "/Applications/org.example.Fonts.app"+ )+ let scanner = scanner(in: directory)++ let groups = await scanner.scan(installedApps: installed, remembered: [tidePool, fonts]).groups++ #expect(groups.map(\.identifier) == ["org.example.tidepool"])+ let items = try #require(groups.first).items+ #expect(Set(items.map { "\($0.kind.rawValue)/\($0.url.lastPathComponent)" }) == [+ "applicationSupport/tide-pool", "library/Tide Pool",+ ])+ #expect(items.allSatisfy { $0.heldBack == .namedLikeTheApp && $0.namedAfter == "org.example.tidepool" })+ #expect(await scanner.stillOrphaned(items, installedApps: installed, remembered: [tidePool]).count == 2)+ }++ @Test func learnsAGoneAppsNameFromTheIdentifiersItLeft() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Caches/org.example.tidewater/cache.db")+ try directory.file("home/Library/Preferences/org.example.tidewater.plist")+ try directory.file("home/Library/Application Support/Tidewater/library.db")+ try directory.file("home/Library/Tidewater/settings.json")+ try directory.file("home/.tidewater/state")+ let scanner = scanner(in: directory)++ let groups = await scanner.scan(installedApps: installed).groups++ #expect(groups.map(\.identifier) == ["org.example.tidewater"])+ let items = try #require(groups.first).items+ let named = items.filter { $0.namedAfter != nil }+ #expect(named.map { "\($0.kind.rawValue)/\($0.url.lastPathComponent)" } == ["applicationSupport/Tidewater"])+ #expect(named.allSatisfy { $0.heldBack == .namedLikeTheApp && $0.namedAfter == "org.example.tidewater" })+ #expect(items.count == 3)+ #expect(await scanner.stillOrphaned(named, installedApps: installed, remembered: []).count == 1)+ let tidewater = InstalledApp(+ url: URL(filePath: "/Applications/Tidewater.app"), bundleIdentifier: "net.other.tidewater", name: "Tidewater"+ )+ #expect(await scanner.stillOrphaned(named, installedApps: installed + [tidewater], remembered: []).isEmpty)+ #expect(await scanner.scan(installedApps: installed + [tidewater]).groups.flatMap(\.items)+ .allSatisfy { $0.namedAfter == nil })+ }++ @Test func learnsNoMakersNameNoNameTwoIdentifiersGiveAndNoGenericName() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Caches/regid.1986-12.org.vendorco/cache.db")+ try directory.file("home/Library/Caches/org.vendorco.editor/cache.db")+ try directory.file("home/Library/Application Support/VendorCo/shared.db")+ try directory.file("home/Library/Caches/org.alpha.studio/cache.db")+ try directory.file("home/Library/Caches/org.beta.studio/cache.db")+ try directory.file("home/Library/Application Support/Studio/projects.db")+ try directory.file("home/Library/Caches/org.example.updater/cache.db")+ try directory.file("home/Library/Application Support/Updater/state.json")+ try directory.file("home/Library/Caches/org.example.reader.ProfileManager/cache.db")+ try directory.file("home/Library/Logs/ProfileManager/main.log")++ let items = await scanner(in: directory).scan(installedApps: installed).groups.flatMap(\.items)++ #expect(items.allSatisfy { $0.namedAfter == nil }, "\(items.filter { $0.namedAfter != nil }.map(\.url))")+ }+@Test func aFolderAnInstalledAppsNameHoldsAsWholeWordsIsNoOrphan() async throws {let directory = try TemporaryDirectory()try directory.file("home/Library/Caches/Atlas/cache.db")