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
A plug-in is an orphan only when Peel saw its app go
Țugui Dragoșeee99d3fcae2
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swiftindex bd0fe35d..ef54a552 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift@@ -103,8 +103,11 @@ public struct OrphanConfidence: Sendable, Hashable {group.total.isComplete ? group.lastModified : nil}+ /// Whole months since the group's last write, from the items whose date moves when they are used: a plug-in's+ /// does not, so a group of plug-ins alone says nothing this way.static func monthsUntouched(_ group: OrphanGroup, now: Date) -> Int? {- guard let written = lastWrite(in: group), written <= now else { return nil }+ let used = group.items.filter { $0.kind != .plugIns }+ guard group.total.isComplete, let written = used.compactMap(\.modificationDate).max(), written <= now else { return nil }// Counts Gregorian months, whatever calendar the user has set. In a lunar calendar, the default in Saudi// Arabia, six months end several days sooner.var calendar = Calendar(identifier: .gregorian)diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swiftindex 441fde9f..58fc8c29 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift@@ -55,11 +55,13 @@ public struct OrphanScanner: Sendable {uniquingKeysWith: { first, _ in first })+ let goneApps = gone.map { $0.bundleIdentifier.lowercased() }+let results = await withTaskGroup(of: LocationResult.self) { group inlet home = environment.homeDirectory.path(percentEncoded: false)for location in environment.locations {_ = group.addTaskUnlessCancelled { [walk] in- await Self.scan(location, ownership: ownership, jobs: jobs, goneBundles: goneBundles, home: home, walk: walk)+ await Self.scan(location, ownership: ownership, jobs: jobs, goneBundles: goneBundles, goneApps: goneApps, home: home, walk: walk)}}return await group.reduce(into: [LocationResult]()) { $0.append($1) }@@ -239,6 +241,17 @@ public struct OrphanScanner: Sendable {return identifier}+ /// Whether a plug-in came with an app Peel saw go: its identifier is that app's, extends it, or is its maker's.+ /// An installer can put a plug-in in place with no app at all, and its date does not move when it is used, so+ /// nothing else says it was left behind.+ static func cameWithAnAppThatLeft(_ identifier: String, goneApps: [String]) -> Bool {+ let plugIn = identifier.lowercased()+ let maker = Identifier.vendor(of: plugIn)+ return goneApps.contains { app in+ plugIn == app || plugIn.hasPrefix(app + ".") || (maker != nil && maker == Identifier.vendor(of: app))+ }+ }+/// Why what the walk saw leaves an item to be chosen by hand: a wallet, a signing key, or a repository inside/// may exist nowhere else, and a folder the walk could not see into is not known to be empty.private static func heldBack(by contents: FolderContents?) -> HoldBack? {@@ -258,6 +271,7 @@ public struct OrphanScanner: Sendable {ownership: AppOwnership,jobs: BackgroundItemOwnership,goneBundles: [String: String],+ goneApps: [String],home: String,walk: LeftoverScanner.Measure) async -> LocationResult {@@ -278,6 +292,7 @@ public struct OrphanScanner: Sendable {let url = location.url.appending(path: name)guard isAFileAFolderOrALink(url) else { continue }guard let identifier = await orphanIdentifier(of: url, kind: location.kind, ownership: ownership, jobs: jobs, goneBundles: goneBundles) else { continue }+ guard location.kind != .plugIns || cameWithAnAppThatLeft(identifier, goneApps: goneApps) else { continue }// The item's own date changes when something is taken out of it, but not when a file inside is// rewritten in place, so the newest date inside comes from the walk.diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swiftindex 77187249..ce91b690 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanConfidenceTests.swift@@ -9,13 +9,14 @@ struct OrphanConfidenceTests {private func group(identifier: String = "com.example.app",+ kind: SearchLocation.Kind = .applicationSupport,written: TimeInterval? = nil,size: Int64 = 1_000,remembered: RememberedApp? = nil) -> OrphanGroup {let item = OrphanItem(url: URL(filePath: "/Users/someone/Library/Application Support/\(identifier)", directoryHint: .isDirectory),- kind: .applicationSupport,+ kind: kind,size: size,modificationDate: written.map { now.addingTimeInterval(-$0) },requiresPrivileges: false@@ -111,6 +112,13 @@ struct OrphanConfidenceTests {#expect(judged.reasons.contains { if case .untouched(let months) = $0 { months >= OrphanConfidence.longUntouched } else { false } })}+ @Test("A plug-in's date does not move when it is used, so its age says nothing")+ func aPlugInsAgeSaysNothing() {+ let judged = OrphanConfidence.judge(group(kind: .plugIns, written: 400 * 24 * 60 * 60), now: now)+ #expect(judged.level == .likely)+ #expect(judged.reasons == [.nothingClaimsIt])+ }+@Test("A folder that did not answer was not read, so nothing is said about when it was last written")func aFolderThatDidNotAnswerSaysNothingAboutItsDates() {let item = OrphanItem(diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swiftindex 3abd745f..07696646 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift@@ -384,27 +384,32 @@ struct OrphanScannerTests {#expect(scan.groups.flatMap(\.items).map(\.url.lastPathComponent) == ["org.example.empty.plist"])}- /// A plug-in is named for what it does, so it is listed under the identifier it declares inside. One whose- /// identifier an installed app claims is not an orphan.- @Test func listsAPlugInUnderTheIdentifierItDeclares() async throws {+ /// A plug-in is named for what it does, so it is listed under the identifier it declares inside, and only when+ /// Peel saw the app it came with go: its identifier is that app's, extends it, or is its maker's. One an installer+ /// put there on its own, with no app, is no orphan however old it is, and neither is one an installed app claims.+ @Test func listsAPlugInOnlyWhenItsAppLeft() async throws {let directory = try TemporaryDirectory()let info = """<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict><key>CFBundleIdentifier</key><string>%@</string></dict></plist>"""- try directory.file(- "root/Library/Audio/Plug-Ins/VST3/Gone.vst3/Contents/Info.plist",- contents: Data(info.replacingOccurrences(of: "%@", with: "com.gonevendor.gone").utf8)- )- try directory.file(- "root/Library/QuickLook/Still Here.qlgenerator/Contents/Info.plist",- contents: Data(info.replacingOccurrences(of: "%@", with: "com.installed.app.quicklook").utf8)+ let plugIns = [+ "root/Library/Audio/Plug-Ins/VST3/Gone.vst3": "com.gonevendor.gone",+ "root/Library/Audio/Plug-Ins/Components/Gone Reverb.component": "com.gonevendor.reverb",+ "root/Library/Audio/Plug-Ins/Components/Standalone.component": "com.independent.synth",+ "root/Library/QuickLook/Still Here.qlgenerator": "com.installed.app.quicklook",+ ]+ for (path, identifier) in plugIns {+ try directory.file("\(path)/Contents/Info.plist", contents: Data(info.replacingOccurrences(of: "%@", with: identifier).utf8))+ }+ let gone = RememberedApp(+ bundleIdentifier: "com.gonevendor.gone", name: "Gone", teamIdentifier: nil, lastSeen: .now, lastPath: "/Applications/Gone.app")- let scan = await scanner(in: directory, registered: ["com.installed.app"]).scan(installedApps: installed)+ let scan = await scanner(in: directory, registered: ["com.installed.app"]).scan(installedApps: installed, remembered: [gone])- #expect(scan.groups.map(\.identifier) == ["com.gonevendor.gone"])- #expect(scan.groups.flatMap(\.items).map(\.url.lastPathComponent) == ["Gone.vst3"])+ #expect(Set(scan.groups.map(\.identifier)) == ["com.gonevendor.gone", "com.gonevendor.reverb"])+ #expect(Set(scan.groups.flatMap(\.items).map(\.url.lastPathComponent)) == ["Gone.vst3", "Gone Reverb.component"])}/// A link to a tool inside an app that is gone leads nowhere, and an app's uninstaller can leave such links