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 a folder only named like an app in place while a program reads it
Țugui Dragoș6eb87880dbb9
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex f06b20b7..eea3e912 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -127,7 +127,9 @@ the Homebrew page's uninstall and cleanups are Homebrew's own.Inside an app, which is code and loses nothing when it moves, a file open only for reading holds nothing, andneither does the program running from an app that uninstalls itself once it has moved (`UninstallsItself`:Mullvad VPN's daemon, and Citrix Workspace's agent and TeamViewer's daemon, each known by the `WatchPaths` of- its job file), whose uninstaller's files are held back (`leftToItsUninstaller`) rather than moved first.+ its job file), whose uninstaller's files are held back (`leftToItsUninstaller`) rather than moved first. A+ folder only named `.app`, such as the web data an app keeps under its identifier, is no app bundle+ (`AppBundleLayout.isAnApp`), so a file open for reading there holds it.- What Peel itself runs from never moves, nor anything holding it, such as the folder a copy built from sourceruns from: only Remove Peel moves Peel (`TrashFailure.Reason.peelRunsFromIt`).- An app carrying a system extension macOS installed is left to Finder (`RemovedElsewhere.byFinder`): Finder'sdiff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppBundleLayout.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppBundleLayout.swiftindex a60c5085..48e5333b 100644--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppBundleLayout.swift+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppBundleLayout.swift@@ -21,6 +21,15 @@ struct AppBundleLayout {}}+ /// An app bundle: named `.app`, with the Info.plist its layout keeps. A folder only named so, such as the web data+ /// or the cache an app keeps under its identifier (`~/Library/WebKit/org.example.tool.app`), is not one.+ static func isAnApp(_ url: URL) -> Bool {+ guard url.pathExtension.caseInsensitiveCompare("app") == .orderedSame else { return false }+ var status = stat()+ let info = AppBundleLayout(of: url).infoFolder.appending(path: "Info.plist")+ return lstat(info.path(percentEncoded: false), &status) == 0+ }+/// The bundle `WrappedBundle` leads to, only when it names a bundle directly in `Wrapper`, so that a link/// leading anywhere else names nothing.static func wrappedBundle(in bundle: URL) -> URL? {diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift b/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swiftindex 704dca84..0935062b 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift@@ -189,7 +189,7 @@ struct OpenFiles {private func holding(_ url: URL, lettingItsProgramsRun: Bool) -> [File] {let names = PathComponents.of(PathPattern.canonical(url).path(percentEncoded: false))- let isAnApp = url.pathExtension.caseInsensitiveCompare("app") == .orderedSame+ let isAnApp = AppBundleLayout.isAnApp(url)return files.filter { file inguard file.names.starts(with: names) else { return false }switch file.hold {diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swiftindex 935c78a7..958d8f54 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift@@ -761,7 +761,7 @@ public struct TrashService: Sendable {await putBackDockTiles(back)}for (item, answer) in zip(items, answers)- where answer == nil && item.originalURL.pathExtension.caseInsensitiveCompare("app") == .orderedSame {+ where answer == nil && AppBundleLayout.isAnApp(item.originalURL) {await registerApp(item.originalURL)}return answers@@ -860,8 +860,7 @@ public struct TrashService: Sendable {guard Self.reason(for: error) == .notPermitted else { return .failed(error.localizedDescription) }// Refused by macOS rather than by the permissions, the helper couldn't do it either.if FileAccess.isProtectedByPrivacy(item.trashedURL) {- let isAnApp = item.trashedURL.pathExtension.caseInsensitiveCompare("app") == .orderedSame- return isAnApp ? .needsAppManagement : .notPermitted+ return AppBundleLayout.isAnApp(item.trashedURL) ? .needsAppManagement : .notPermitted}}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OpenFilesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OpenFilesTests.swiftindex ef73d882..753b2053 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OpenFilesTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OpenFilesTests.swift@@ -74,6 +74,7 @@ struct OpenFilesTests {let directory = try TemporaryDirectory()let code = try directory.file("Example.app/Contents/PlugIns/Open.appex/Contents/MacOS/Open")let state = try directory.file("Example.app/Contents/Resources/state.db")+ try directory.file("Example.app/Contents/Info.plist")let app = directory.url.appending(path: "Example.app", directoryHint: .isDirectory)let reading = try FileHandle(forReadingFrom: code)defer { try? reading.close() }@@ -86,6 +87,16 @@ struct OpenFilesTests {#expect(!OpenFiles(excluding: nil).holders(of: app, lettingItsProgramsRun: true).isEmpty)}+ @Test func aFolderOnlyNamedLikeAnAppIsHeldByAFileOpenForReading() throws {+ let directory = try TemporaryDirectory()+ let store = try directory.file("Library/WebKit/org.example.tool.app/WebsiteData/LocalStorage/store.db")+ let reading = try FileHandle(forReadingFrom: store)+ defer { try? reading.close() }++ let folder = directory.url.appending(path: "Library/WebKit/org.example.tool.app", directoryHint: .isDirectory)+ #expect(!OpenFiles(excluding: nil).holders(of: folder).isEmpty)+ }+/// Nothing is written into the app here: once a program inside it starts, macOS revokes a descriptor open for/// writing on a file in the app and may refuse a new one.@Test func aProgramRunningFromInsideAnAppHoldsItUnlessItsProgramsMayRun() throws {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swiftindex e9313918..db9ef14a 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift@@ -494,6 +494,7 @@ struct TrashServiceTests {@Test func anAppPutBackIsRegisteredWithLaunchServicesOnceItIsBack() async throws {let directory = try TemporaryDirectory()let app = try directory.directory("home/Applications/org.example.Studio.app")+ try directory.file("home/Applications/org.example.Studio.app/Contents/Info.plist")let cache = try directory.directory("home/Library/Caches/org.example.Studio")let trash = try directory.directory("home/.Trash")let registered = Mutex<[String]>([])@@ -517,9 +518,32 @@ struct TrashServiceTests {#expect(registered.withLock { $0 } == [app.path(percentEncoded: false)])}+ @Test func aFolderOnlyNamedLikeAnAppIsNotRegisteredWhenPutBack() async throws {+ let directory = try TemporaryDirectory()+ let data = try directory.directory("home/Library/WebKit/org.example.tool.app")+ let trash = try directory.directory("home/.Trash")+ let registered = Mutex<[String]>([])+ let service = TrashService(+ environment: SearchEnvironment(+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)+ ),+ registerApp: { url in registered.withLock { $0.append(url.path(percentEncoded: false)) } }+ ) { url in+ let destination = trash.appending(path: url.lastPathComponent)+ try FileManager.default.moveItem(at: url, to: destination)+ return destination+ }++ let moved = await service.trash([data]).trashed+ #expect(await service.restore(moved) == [nil])+ #expect(registered.withLock { $0 }.isEmpty)+ }+@Test func registersTheAppsPutBackOnlyOnceEveryItemIsBack() async throws {let directory = try TemporaryDirectory()let app = try directory.directory("home/Applications/org.example.Studio.app")+ try directory.file("home/Applications/org.example.Studio.app/Contents/Info.plist")let container = try directory.directory("home/Library/Containers/org.example.Studio.Extension")let trash = try directory.directory("home/.Trash")let containerWasBack = Mutex<[Bool]>([])diff --git a/SAFETY.md b/SAFETY.mdindex 47c2b3f8..6edc7a72 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -168,16 +168,17 @@ how to free the item: quit it, or stop it in Background Items when it has no winprogram again. A build tool's daemon, which stays after a build and keepsthe tool's caches open, is named by its tool with the command that tool documents for stopping it: Gradle's andKotlin's stop with `gradle --stop`, Bazel's with `bazel shutdown`, and mvnd's with `mvnd --stop`.-Moving a database or a cache from under an agent, a daemon, or a server that is using it would break it. A program-of macOS's own, such as a service keeping its cache open, is named as macOS: nobody quits it, so the item stays-where it is. An app is code, which loses nothing when it moves, so a program that only reads inside it, as Safari-reads an app's Safari extension, does not keep it in place; one that runs from it or writes in it does. A program-running from an app that uninstalls itself once it is moved, as Mullvad VPN, Citrix Workspace, and TeamViewer do,-doesn't keep that app in place, since their own uninstaller stops it; one writing in it still does. When nothing but-an app's own background programs, the launch agents and daemons that run from inside it, keeps the app-in place, an uninstall stops them first and then moves the app, and starts them again if it still stays. Peel itself-counts too: whatever Peel runs from, and any folder holding it, stays, since only Remove Peel moves Peel. Of-programs that run as another account or as root, macOS's own among them, only the program can be seen, never the+Moving a database or a cache from under an agent, a daemon, or a server that is using it would break it. A program of+macOS's own, such as a service keeping its cache open, is named as macOS: nobody quits it, so the item stays where it+is. An app is code, which loses nothing when it moves, so a program that only reads inside it, as Safari reads an+app's Safari extension, does not keep it in place; one that runs from it or writes in it does. A folder only named+like an app, such as the web data or the cache an app keeps under its identifier, is no app, so a program reading+there keeps it in place. A program running from an app that uninstalls itself once it is moved, as Mullvad VPN, Citrix+Workspace, and TeamViewer do, doesn't keep that app in place, since their own uninstaller stops it; one writing in it+still does. When nothing but an app's own background programs, the launch agents and daemons that run from inside it,+keeps the app in place, an uninstall stops them first and then moves the app, and starts them again if it still stays.+Peel itself counts too: whatever Peel runs from, and any folder holding it, stays, since only Remove Peel moves Peel.+Of programs that run as another account or as root, macOS's own among them, only the program can be seen, never thefiles it holds open, which is why Space also leaves macOS's own caches unselected, and in the Library at the top ofthe disk, where those programs keep theirs, does not list them at all. Neither you nor Peel can quit such a program,so Peel never asks you to: what it runs from stays, and says so, until it is stopped in Background Items or by the