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 macOS keeps when an uninstall leaves it empty
Țugui Dragoș0b122e36c787
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/MakersFolders.swift b/Packages/PeelCore/Sources/PeelCore/Removal/MakersFolders.swiftindex 2b4f63a1..583bfefd 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/MakersFolders.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/MakersFolders.swift@@ -17,17 +17,24 @@ struct MakersFolders {Set(apps.filter { !$0.isApples }.flatMap(\.ownFolderNames))}- /// Deepest first. A folder with another name stops the walk, since it may be any app's.+ /// Deepest first. A folder with another name stops the walk, since it may be any app's, and so does one macOS+ /// keeps under that name directly in its location (`SystemFolders`).func above(_ moved: [URL]) -> [URL] {let locations = environment.locationslet ends = Set(locations.map { PathPattern.comparablePath(of: $0.url) })let places = locations.filter { Self.kinds.contains($0.kind) }.map { PathPattern.comparablePath(of: $0.url) }+ let kindsAt = Dictionary(grouping: locations, by: { PathPattern.comparablePath(of: $0.url) })+ .mapValues { $0.map(\.kind) }+ func isMacOSs(_ folder: URL) -> Bool {+ let parent = PathPattern.comparablePath(of: folder.deletingLastPathComponent())+ return (kindsAt[parent] ?? []).contains { SystemFolders.keeps(folder.lastPathComponent, in: $0) }+ }var folders: [String: URL] = [:]for url in moved {var folder = url.deletingLastPathComponent()var path = PathPattern.comparablePath(of: folder)while !ends.contains(path), places.contains(where: { PathComponents.isPath(path, inside: $0) }),- names.contains(Naming.folderName(folder.lastPathComponent)) {+ names.contains(Naming.folderName(folder.lastPathComponent)), !isMacOSs(folder) {folders[path] = folderfolder = folder.deletingLastPathComponent()path = PathPattern.comparablePath(of: folder)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swiftindex aa992d5d..dd5b1284 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift@@ -1034,6 +1034,22 @@ struct UninstallationTests {}}+ @Test func anEmptiedFolderMacOSKeepsUnderTheAppsNameStays() async throws {+ let directory = try TemporaryDirectory()+ let bundle = try directory.directory("Applications/Knowledge.app")+ let own = try directory.directory("home/Library/Application Support/Knowledge/org.example.knowledge")+ let plan = uninstallation(+ app: InstalledApp(url: bundle, bundleIdentifier: "org.example.knowledge", name: "Knowledge"),+ leftovers: [file(own, .applicationSupport)]+ )++ let went = await plan.move([bundle, own], using: try service(in: directory, refusing: nil))++ #expect(went.failures.isEmpty)+ #expect(Set(went.trashed.map(\.originalURL)) == [bundle, own])+ #expect(!directory.url.appending(path: "home/Library/Application Support/Knowledge").isMissing)+ }+/// A maker's folder can be named for the developer the app's signature names rather than for its identifier,/// as in `BraveSoftware/Brave-Browser`: once the profile has moved, the empty folder around it goes too.@Test func aMakersFolderNamedForTheDeveloperIsTheMakers() throws {