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 what stayed when a page changed under its Move to Trash question
Țugui Dragoș778ccd9c89df
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift b/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swiftindex acd1aad7..c08012be 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift@@ -47,6 +47,18 @@ public struct CarriedSelection: Sendable {Part(page: page, title: title, source: source, sourceKey: sourceKey, sizes: sizes, movesLast: movesLast)}+ /// The items of this part `result` neither moved, refused, nor took along in a folder it moved.+ func unaccounted(by result: TrashResult) -> [URL] {+ let moved = Set(result.trashed.map { CarriedSelection.writtenPath(of: $0.originalURL) })+ let refused = Set(result.failures.map { CarriedSelection.writtenPath(of: $0.url) })+ return sizes.keys.filter { url in+ let path = CarriedSelection.writtenPath(of: url)+ return !moved.contains(path) && !refused.contains(path)+ && !CarriedSelection.folders(above: path).contains(where: moved.contains)+ }+ .sorted { $0.path(percentEncoded: false) < $1.path(percentEncoded: false) }+ }+public var removalPart: RemovalPart {RemovalPart(source: source, sourceKey: sourceKey, tool: page.tool)}@@ -181,7 +193,9 @@ public struct CarriedSelection: Sendable {public static func pass(_ parts: [Part], move: (Part) async -> TrashResult?) async -> Pass {var pass = Pass()for part in parts {- if let result = await move(part) {+ if var result = await move(part) {+ // A tool moves what its page lists and selects now, so what changed since the question stays.+ result.failures += part.unaccounted(by: result).map { TrashFailure(url: $0, reason: .changedSinceScan) }pass.moved.append((part, result))} else {pass.kept.append(part)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CarriedSelectionTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CarriedSelectionTests.swiftindex ea309262..95b8e89a 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CarriedSelectionTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CarriedSelectionTests.swift@@ -121,6 +121,21 @@ struct CarriedSelectionTests {#expect(pass.moved.map(\.part.page.scope) == ["Peel"])}+ @Test func anItemAskedForThatChangedSinceIsSaidToHaveStayed() async {+ let parts = [part("orphans", "org.example.chat", ["Chat": 100, "Chat/cache": 10, "chat.plist": 1, "gone": 5])]+ let pass = await CarriedSelection.pass(parts) { part in+ let folder = URL(filePath: "/Users/x/Chat")+ let preferences = URL(filePath: "/Users/x/chat.plist")+ return TrashResult(+ trashed: [TrashedItem(originalURL: folder, trashedURL: folder, date: .now)],+ failures: [TrashFailure(url: preferences, reason: .locked)]+ )+ }++ #expect(pass.result.failures.map(\.url.lastPathComponent).sorted() == ["chat.plist", "gone"])+ #expect(pass.result.failures.first { $0.url.lastPathComponent == "gone" }?.reason == .changedSinceScan)+ }+/// What a pass did is told once, whichever parts it came from: every item the parts moved, and every one/// their tools refused.@Test func aPassTellsWhatEveryPartMovedAndRefused() async {