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
Tell which apps are in the Trash without building the removal guard
Țugui Dragoș532d294f8719
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swiftindex 80d7eb80..4b197263 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift@@ -811,17 +811,24 @@ public struct TrashService: Sendable {/// folder is compared with links resolved, since one that is only called `.Trash` can be a link into/// Messages. `FileManager` is not asked: for a folder in iCloud Drive it names iCloud's Trash, not Peel's.public func isInATrash(_ url: URL) -> Bool {- guard let folder = resolvedFolder(of: url) else { return false }+ guard let folder = Self.resolvedFolder(of: url) else { return false }return trashes(forItemsIn: folder).contains(folder)}/// Whether `url` is in a Trash, directly or in a folder there, where nothing can be moved again.public func isInsideATrash(_ url: URL) -> Bool {+ Self.isInsideATrash(url, home: environment.homeDirectory)+ }++ /// `isInsideATrash(_:)` for `home`, without the `RemovalGuard` a service builds, for code that only asks this.+ public static func isInsideATrash(_ url: URL, home: URL = .homeDirectory) -> Bool {guard let folder = resolvedFolder(of: url) else { return false }- return trashes(forItemsIn: folder).contains { PathComponents.isPath(folder, atOrInside: $0) }+ return trashes(forItemsIn: folder, homes: [.homeDirectory, home]).contains {+ PathComponents.isPath(folder, atOrInside: $0)+ }}- private func resolvedFolder(of url: URL) -> String? {+ private static func resolvedFolder(of url: URL) -> String? {guard !url.pathComponents.contains(where: { $0 == "." || $0 == ".." }) else { return nil }return PrivilegedPathPolicy.resolvedPath(url.deletingLastPathComponent().path(percentEncoded: false))}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swiftindex 4e0d4fc3..fc878a6a 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift@@ -99,7 +99,7 @@ public struct Uninstallation: Sendable {isAppMeasured: await bundle.map { !$0.couldNotBeRead } ?? false,appSharesStorage: await bundle?.sharesMostOfItsStorage ?? false,isAppBeyondTheHelper: appRequiresPrivileges && !app.isSystemProtected && reach.isBeyond(app.url),- isAppInTheTrash: TrashService(environment: environment).isInsideATrash(app.url),+ isAppInTheTrash: TrashService.isInsideATrash(app.url, home: environment.homeDirectory),uninstallsItself: uninstallsItself,installedSystemExtensions: await AppExtensions.installed(carriedBy: app, asking: systemExtensions))diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swiftindex 082c132e..3ff10b00 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift@@ -21,6 +21,10 @@ struct TrashServiceTests {#expect(!service.isInsideATrash(lookalike))#expect(service.isInATrash(direct))#expect(!service.isInATrash(nested))+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ for url in [direct, nested, installed, lookalike] {+ #expect(TrashService.isInsideATrash(url, home: home) == service.isInsideATrash(url), "\(url.path)")+ }}private func service(in directory: borrowing TemporaryDirectory) throws -> TrashService {diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swiftindex 875340bb..65537655 100644--- a/Peel/Model/AppLibrary.swift+++ b/Peel/Model/AppLibrary.swift@@ -315,8 +315,7 @@ final class AppLibrary {@discardableResultprivate func adopt(_ found: [InstalledApp]) -> [InstalledApp] {revealed = stillThere(revealed, beside: found)- let trash = TrashService()- appsInATrash = Set(revealed.filter { trash.isInsideATrash($0.url) }.map(\.id))+ appsInATrash = Set(revealed.filter { TrashService.isInsideATrash($0.url) }.map(\.id))let listed = AppCatalog.sorted(found + revealed)let previous = Dictionary(apps.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })let changed = listed.filter { app in previous[app.id].map { !$0.isTheSameBuild(as: app) } ?? false }