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
Say which open app kept a Space folder from moving
Țugui Dragoș5eb19240e70f
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swiftindex 21ebb1e3..08fabe0f 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift@@ -141,28 +141,29 @@ public enum SpaceRemoval {return sizes}- /// What of `item` can move now, measuring nothing: the check a move makes just before it moves, since an app- /// opened since the plan may be writing to some of these folders.+ /// What of `item` can move now, measuring nothing, and what an app open now keeps: the check a move makes just+ /// before it moves, since an app opened since the plan may be writing to some of these folders.@concurrent- public static func removable(+ public static func movableNow(in item: SpaceItem,environment: SearchEnvironment = .current,exclusions: Exclusions = .none,running: [RunningCopies.Process]- ) async -> [URL] {- await removable(+ ) async -> (removable: [URL], inUse: [(url: URL, name: String)]) {+ await movableNow(in: item, environment: environment, exclusions: exclusions, running: namesOfRunningApps(running))}@concurrent- static func removable(+ static func movableNow(in item: SpaceItem,environment: SearchEnvironment,exclusions: Exclusions = .none,running: [String: String] = [:]- ) async -> [URL] {- children(of: item, environment: environment, exclusions: exclusions, running: running).removable+ ) async -> (removable: [URL], inUse: [(url: URL, name: String)]) {+ let children = children(of: item, environment: environment, exclusions: exclusions, running: running)+ return (children.removable, children.inUse)}private static func children(diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swiftindex 274e92fa..6c0baf0c 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift@@ -63,10 +63,10 @@ struct SpaceRemovalTests {)let plan = await SpaceRemoval.plan(for: machines, environment: environment(directory))- let removable = await SpaceRemoval.removable(in: machines, environment: environment(directory))+ let now = await SpaceRemoval.movableNow(in: machines, environment: environment(directory))#expect(plan.removable.isEmpty)- #expect(removable.isEmpty)+ #expect(now.removable.isEmpty)}/// Space moves each folder inside Caches whole, but Coursier's folder holds the JVMs that `JAVA_HOME` points@@ -563,14 +563,27 @@ struct SpaceRemovalTests {let running = ["comspotifyclient": "Spotify"]let plan = await SpaceRemoval.plan(for: item(directory), environment: environment(directory), running: running)- let removable = await SpaceRemoval.removable(- in: item(directory),- environment: environment(directory),- running: running+ let now = await SpaceRemoval.movableNow(+ in: item(directory), environment: environment(directory), running: running+ )++ #expect(now.removable.map(\.lastPathComponent) == ["com.gone.app"])+ #expect(now.removable == plan.removable)+ }++ @Test func theMovesCheckNamesTheAppOpenedSinceThePlan() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Caches/com.spotify.client/audio.db")+ try directory.file("home/Library/Caches/com.gone.app/old.db")+ let plan = await SpaceRemoval.plan(for: item(directory), environment: environment(directory), running: [:])++ let now = await SpaceRemoval.movableNow(+ in: item(directory), environment: environment(directory), running: ["comspotifyclient": "Spotify"])- #expect(removable.map(\.lastPathComponent) == ["com.gone.app"])- #expect(removable == plan.removable)+ #expect(plan.removable.map(\.lastPathComponent).sorted() == ["com.gone.app", "com.spotify.client"])+ #expect(now.removable.map(\.lastPathComponent) == ["com.gone.app"])+ #expect(now.inUse.map { "\($0.url.lastPathComponent): \($0.name)" } == ["com.spotify.client: Spotify"])}/// Many cache and log folders are named after the app rather than its bundle identifier, such as `Firefox`,diff --git a/Peel/Model/SpaceLibrary.swift b/Peel/Model/SpaceLibrary.swiftindex f8728da1..7379a8a2 100644--- a/Peel/Model/SpaceLibrary.swift+++ b/Peel/Model/SpaceLibrary.swift@@ -188,16 +188,21 @@ extension SpaceLibrary: CarriesSelection {}/// Asks the area again rather than trusting its plan: an app opened since may be writing to some of these- /// folders, and they are left where they are.+ /// folders, and they stay where they are, each told as in use by that app.func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {guard let item = report?.items.first(where: { $0.page == part.page }) else { return TrashResult() }isRemoving = truedefer { isRemoving = false }let exclusions = ExclusionsStore.shared.exclusions- let removable = await SpaceRemoval.removable(in: item, exclusions: exclusions, running: RunningCopies.current)- .filter { selectedURLs.contains($0) && part.sizes.keys.contains($0) }- return await TrashService(exclusions: exclusions)+ let chosen = selectedURLs.intersection(part.sizes.keys)+ let now = await SpaceRemoval.movableNow(in: item, exclusions: exclusions, running: RunningCopies.current)+ let removable = now.removable.filter(chosen.contains)+ var result = await TrashService(exclusions: exclusions).trash(removable, usingHelperFor: Set(removable.filter(FileAccess.requiresPrivilegesToRemove)))+ result.failures += now.inUse.filter { chosen.contains($0.url) }.map {+ TrashFailure(url: $0.url, reason: .heldOpen(by: [$0.name]))+ }+ return result}func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {