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
Keep the files of an app on a disk that isn't connected out of Orphaned Files
Țugui Dragoș1c28d0947c7b
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex ab871ddb..748d3072 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -356,7 +356,9 @@ macOS asks the user to approve it once. It talks to the app over XPC.earlier revision gave about an app it couldn't check, or about one this revision asks nobody about, is dropped, sothe app is asked again at the next round.- **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.+ name it (`AppMemory`), and selects nothing for the person. An app macOS knows on another disk that claims something+ is remembered too (`OrphanScan.appsOnOtherDisks`, `Disks`), so its files stay its own while that disk isn't+ connected, and a link into an app on such a disk is not one into an app that is gone.- **Resetting an app.** `AppReset` selects an app's settings, caches, and window state, which the app makes againwhen it next opens, and offers its website data and the data it keeps for the person without selecting them. Itnever offers the app itself, only files certainly the app's that nothing else claims, and it saves each preference@@ -395,7 +397,7 @@ where a Homebrew install takes them from.| `~/Library/Application Support/Peel/exclusions.json` | The user's exclusions. || `~/Library/Application Support/Peel/Preference Backups/` | The settings Peel saved before resetting an app, and before putting a saved copy back. || `~/Library/Application Support/Peel/digests.bin` | What Duplicates already read, so an unchanged file isn't read again. |-| `~/Library/Application Support/Peel/apps.json` | The apps Peel has seen, kept once they are gone, so Orphaned Files can name what they left (`AppMemory`). |+| `~/Library/Application Support/Peel/apps.json` | The apps Peel has seen, and those macOS knows on another disk that claimed a file, kept once they are gone or out of reach, so Orphaned Files can name what they left (`AppMemory`). || `~/Library/Application Support/Peel/teams.json` | Which team signs each app, so a change of signer can be told (`TeamRegistry`). || `~/Library/Application Support/Peel/orphan-owners.json` | The orphaned files the user said belong to an installed app. || `~/Library/Application Support/Peel/left-for-an-administrator.json` | What an uninstall left that only an administrator can move, from a place the helper doesn't serve, so Orphaned Files lists it under Needs an Administrator once the app is gone. |diff --git a/GUIDE.md b/GUIDE.mdindex e9a9b686..dcc6918a 100644--- a/GUIDE.md+++ b/GUIDE.md@@ -93,15 +93,16 @@ 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 sawinstalled and then saw go, or, for the copy macOS keeps of a system extension, by the app macOS's own record- names. 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 row says how. Peel doesn't list- what only a guess could tie to an app, so look for it yourself: a folder named only for a maker, such as `Google`- in Application Support, a data folder only the app's documentation names, such as Tor Browser's `TorBrowser-Data`,- a folder named like a gone app while another installed app's name holds that name, such as one called Epic beside- Epic Games Launcher, and a hidden folder in your home named like an app, since one such as `~/.local` is shared by- many command-line tools. What only an administrator can move, from a place Peel's helper isn't allowed to move it- from, is listed apart under Needs an Administrator, with how to remove it in Finder, and so is what an uninstall- left there, which nothing else would tie to the app once it is gone.+ names. An app on another disk keeps its files out of the list while that disk isn't connected, once Orphaned Files+ has 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 row+ says how. Peel doesn't list what only a guess could tie to an app, so look for it yourself: a folder named only for+ a maker, such as `Google` in Application Support, a data folder only the app's documentation names, such as Tor+ Browser's `TorBrowser-Data`, a folder named like a gone app while another installed app's name holds that name,+ such as one called Epic beside Epic Games Launcher, and a hidden folder in your home named like an app, since one+ such as `~/.local` is shared by many command-line tools. What only an administrator can move, from a place Peel's+ helper isn't allowed to move it from, is listed apart under Needs an Administrator, with how to remove it in+ Finder, and so is what an uninstall left there, which nothing else would tie to the app once it is gone.- **Developer:** caches of developer tools, editors, browsers, and AI models. Nothing is selected for you, and SelectRecommended passes by what you may want again; toolchains or anything holding an account are never listed.- **Build Artifacts:** what builds left in your projects, like `node_modules`, `DerivedData`, or `target`, each onlydiff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swiftindex c86221ac..f5754cf8 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift@@ -105,13 +105,15 @@ public struct OrphanScan: Sendable {public var cutShortLocations: [SearchLocation] = []/// What only an administrator can move, listed apart from the groups.public var forAnAdministrator: [AdministratorItem] = []+ /// Apps macOS knows on another disk that claimed something: Peel remembers them for when that disk isn't connected.+ public var appsOnOtherDisks: [InstalledApp] = []/// The same scan without the group `id`, as when the person said it belongs to an app.public func without(_ id: OrphanGroup.ID) -> OrphanScan {OrphanScan(groups: groups.filter { $0.id != id }, unreadableLocations: unreadableLocations,needsFullDiskAccess: needsFullDiskAccess, cutShortLocations: cutShortLocations,- forAnAdministrator: forAnAdministrator+ forAnAdministrator: forAnAdministrator, appsOnOtherDisks: appsOnOtherDisks)}}diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swiftindex a4a8a3ff..d0ed1bbf 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift@@ -1,5 +1,6 @@import Foundationinternal import PeelPrivileged+import Synchronizationpublic struct OrphanScanner: Sendable {private static let systemPrefixes = [@@ -10,6 +11,8 @@ public struct OrphanScanner: Sendable {public let environment: SearchEnvironmentpublic let exclusions: Exclusionsprivate let isRegisteredApp: @Sendable (String) -> Bool+ private let knownPlaces: @Sendable (String) -> [URL]+ private let isOnAnotherDisk: @Sendable (URL) -> Bool/// The apps that come with macOS, which can claim files like any other app. Nil means `AppCatalog.systemApps`.private let systemApps: [InstalledApp]?private let walk: LeftoverScanner.Measure@@ -34,11 +37,15 @@ public struct OrphanScanner: Sendable {walk: @escaping LeftoverScanner.Measure = LeftoverScanner.walk,nestedFolderLimit: Int = NestedSearch.folderLimit,systemExtensions: @escaping AppExtensions.SystemExtensionsAnswer = AppExtensions.askingMacOS,- installedByApple: @escaping LeftoverScanner.InstalledByApple = { await PackageReceipts.isInstalledByApple($0) }+ installedByApple: @escaping LeftoverScanner.InstalledByApple = { await PackageReceipts.isInstalledByApple($0) },+ knownPlaces: @escaping @Sendable (String) -> [URL] = AppInspector.applicationURLs(forBundleIdentifier:),+ isOnAnotherDisk: @escaping @Sendable (URL) -> Bool = Disks.isOnAnotherDisk) {self.environment = environmentself.exclusions = exclusionsself.isRegisteredApp = isRegisteredApp+ self.knownPlaces = knownPlaces+ self.isOnAnotherDisk = isOnAnotherDiskself.systemApps = systemAppsself.walk = walkself.nestedFolderLimit = nestedFolderLimit@@ -69,8 +76,14 @@ public struct OrphanScanner: Sendable {let (installedApps, gone) = Self.split(remembered, installedApps: installedApps)let here = Set(installedApps.compactMap { $0.bundleIdentifier?.lowercased() })let goneApps = gone.map { $0.bundleIdentifier.lowercased() }+ let knownToMacOS = AppsKnownToMacOS()let ownership = AppOwnership(- installedApps: installedApps + systemApps, goneApps: goneApps, isRegisteredApp: isRegisteredApp+ installedApps: installedApps + systemApps, goneApps: goneApps,+ isRegisteredApp: { [isRegisteredApp] identifier in+ guard isRegisteredApp(identifier) else { return false }+ knownToMacOS.note(identifier)+ return true+ })let jobs = BackgroundItemOwnership(installedApps: installedApps + systemApps).knowingJobs(in: launchdFolders)let goneBundles = Dictionary(@@ -193,7 +206,9 @@ public struct OrphanScanner: Sendable {needsFullDiskAccess: unreadableLocations.contains { FullDiskAccess.canList($0.url) == .missing },cutShortLocations: cutShortLocations.sorted(by: byPath),forAnAdministrator: (Self.claiming(apart, by: records) + recorded)- .sorted { Self.comesBefore($0.item, $1.item) }+ .sorted { Self.comesBefore($0.item, $1.item) },+ appsOnOtherDisks: knownToMacOS.identifiers.flatMap(knownPlaces).filter(isOnAnotherDisk)+ .compactMap { AppInspector.inspect($0) })}@@ -534,7 +549,7 @@ public struct OrphanScanner: Sendable {}/// The app bundle a link leads into, when that bundle is gone. Nil for a link into an app that is still- /// there, or into no app at all.+ /// there, one on a disk that isn't connected, or into no app at all.static func goneApp(behind link: URL) -> URL? {guardlet destination = try? FileManager.default.destinationOfSymbolicLink(@@ -548,6 +563,7 @@ public struct OrphanScanner: Sendable {filePath: NSString.path(withComponents: Array(components[...app])),directoryHint: .isDirectory)+ guard !bundle.isOnADiskNotConnected else { return nil }return FileManager.default.fileExists(atPath: bundle.path(percentEncoded: false)) ? nil : bundle}@@ -830,3 +846,14 @@ struct GoneFolders: Sendable {return named}}++/// The apps macOS knows, by identifier, that claimed something during one scan.+private final class AppsKnownToMacOS: Sendable {+ private let claimed = Mutex<Set<String>>([])++ var identifiers: [String] { claimed.withLock { $0.sorted() } }++ func note(_ identifier: String) {+ _ = claimed.withLock { $0.insert(identifier) }+ }+}diff --git a/Packages/PeelCore/Sources/PeelCore/Support/Disks.swift b/Packages/PeelCore/Sources/PeelCore/Support/Disks.swiftnew file mode 100644index 00000000..bc650601--- /dev/null+++ b/Packages/PeelCore/Sources/PeelCore/Support/Disks.swift@@ -0,0 +1,31 @@+import DiskArbitration+import Foundation+internal import PeelPrivileged++/// What a mounted volume is, as DiskArbitration describes it.+enum Disks {+ /// Whether `url` is on a disk mounted under `/Volumes` that is not a disk image, which is mounted to install from+ /// and then thrown away.+ static func isOnAnotherDisk(_ url: URL) -> Bool {+ let names = PathComponents.of(url.path(percentEncoded: false))+ guard names.count > 2, names[0] == "Volumes", let volume = volume(mountedAt: "/Volumes/\(names[1])")+ else { return false }+ return !isADiskImage(volume)+ }++ /// DiskArbitration's description of the volume mounted at `path`, or nil when none is mounted exactly there.+ static func volume(mountedAt path: String) -> [String: Any]? {+ guard let session = DASessionCreate(kCFAllocatorDefault),+ let disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, URL(filePath: path) as CFURL),+ let description = DADiskCopyDescription(disk) as? [String: Any],+ let mountPoint = description[kDADiskDescriptionVolumePathKey as String] as? URL,+ PathPattern.comparablePath(of: mountPoint) == PathPattern.comparablePath(of: URL(filePath: path))+ else { return nil }+ return description+ }++ static func isADiskImage(_ volume: [String: Any]) -> Bool {+ volume[kDADiskDescriptionDeviceModelKey as String] as? String == "Disk Image"+ || (volume[kDADiskDescriptionDevicePathKey as String] as? String)?.contains("/IOHDIXController/") == true+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DisksTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DisksTests.swiftnew file mode 100644index 00000000..28b1ee10--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/DisksTests.swift@@ -0,0 +1,23 @@+import Foundation+@testable import PeelCore+import Testing++struct DisksTests {+ @Test func tellsADiskImageFromTheDiskMacOSStartedFrom() throws {+ let directory = try TemporaryDirectory()+ let volume = try ScratchVolume(fileSystem: "APFS", mountedAt: directory.url.appending(path: "Image"))++ let image = try #require(Disks.volume(mountedAt: volume.url.path(percentEncoded: false)))+ let startup = try #require(Disks.volume(mountedAt: "/"))+ #expect(Disks.isADiskImage(image))+ #expect(!Disks.isADiskImage(startup))+ }++ @Test func aFolderWhereNoVolumeIsMountedIsNoDisk() throws {+ let directory = try TemporaryDirectory()++ #expect(Disks.volume(mountedAt: directory.url.path(percentEncoded: false)) == nil)+ #expect(!Disks.isOnAnotherDisk(URL(filePath: "/Volumes/org.example.NotConnected/Apps/Extern.app")))+ #expect(!Disks.isOnAnotherDisk(URL(filePath: "/Applications/Extern.app")))+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swiftindex 4485447a..196531e5 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift@@ -1401,6 +1401,38 @@ struct OrphanScannerTests {#expect(scan.groups.map(\.identifier) == ["org.example-gone.app"])}+ @Test func notesTheAppsMacOSKnowsOnAnotherDiskThatClaimFiles() async throws {+ let directory = try TemporaryDirectory()+ let info = """+ <?xml version="1.0" encoding="UTF-8"?>+ <plist version="1.0"><dict><key>CFBundleIdentifier</key><string>org.example.extern</string>+ <key>CFBundleName</key><string>Extern</string></dict></plist>+ """+ let extern = try directory.file("Disk/Applications/Extern.app/Contents/Info.plist", contents: Data(info.utf8))+ .deletingLastPathComponent().deletingLastPathComponent()+ try directory.file("home/Library/Preferences/org.example.extern.plist")+ let environment = SearchEnvironment(+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)+ )+ let scan = { (onAnotherDisk: Bool) in+ await OrphanScanner(+ environment: environment,+ isRegisteredApp: { $0 == "org.example.extern" },+ systemApps: [],+ knownPlaces: { $0 == "org.example.extern" ? [extern] : [] },+ isOnAnotherDisk: { _ in onAnotherDisk }+ ).scan(installedApps: installed)+ }++ let elsewhere = await scan(true)+ let here = await scan(false)++ #expect(elsewhere.groups.isEmpty)+ #expect(elsewhere.appsOnOtherDisks.map(\.bundleIdentifier) == ["org.example.extern"])+ #expect(here.appsOnOtherDisks.isEmpty)+ }+@Test(.permissionsHold) func anAppInAPlacePeelCannotReadHasNotLeft() async throws {let directory = try TemporaryDirectory()var remembered: [RememberedApp] = []@@ -1550,6 +1582,20 @@ struct OrphanScannerTests {#expect(Set(try #require(groups["com.remembered.app"]).items.map(\.url.lastPathComponent)) == ["rem", "com.remembered.app"])}+ @Test func aLinkIntoAnAppOnADiskThatIsNotConnectedIsNotListed() async throws {+ let directory = try TemporaryDirectory()+ let bin = try directory.directory("root/opt/homebrew/bin")+ let disk = "/Volumes/org.example.NotConnected-\(UUID().uuidString)"+ try FileManager.default.createSymbolicLink(+ atPath: bin.appending(path: "extern").path(percentEncoded: false),+ withDestinationPath: "\(disk)/Applications/Extern.app/Contents/MacOS/extern"+ )++ let scan = await scanner(in: directory).scan(installedApps: installed)++ #expect(scan.groups.isEmpty)+ }+/// A shell completion an app's installer linked into zsh's folder leads nowhere once the app is gone, and zsh/// then complains in every new shell. It is listed as a tool's link is.@Test func listsAShellCompletionThatLeadsIntoAnAppThatIsGone() async throws {diff --git a/Peel/Model/OrphanLibrary.swift b/Peel/Model/OrphanLibrary.swiftindex fbc5b5eb..48af5039 100644--- a/Peel/Model/OrphanLibrary.swift+++ b/Peel/Model/OrphanLibrary.swift@@ -61,13 +61,17 @@ final class OrphanLibrary {// What is currently running is better evidence than anything worked out from what is installed: a// helper or an agent can keep a folder that no app bundle claims.let running = Set(NSWorkspace.shared.runningApplications.compactMap(\.bundleIdentifier))- return await OrphanScanner(exclusions: ExclusionsStore.shared.exclusions).scan(+ let scan = await OrphanScanner(exclusions: ExclusionsStore.shared.exclusions).scan(installedApps: installedApps,remembered: remembered,running: running,owners: owners,leftForAnAdministrator: await LeftForAnAdministrator().load())+ if !scan.appsOnOtherDisks.isEmpty {+ await AppMemory().remember(scan.appsOnOtherDisks)+ }+ return scan}), library.unreadable.isEmpty else { return }let remainingURLs = Set(result.groups.flatMap(\.items).filter { $0.leftAlone == nil }.map(\.url))scan = result