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
An unreadable list of refusals is an error, never nothing refused
Țugui Dragoșc82267914bef
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swiftindex 015879e7..7693f0de 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift@@ -220,10 +220,11 @@ struct HistoryCommand: AsyncParsableCommand {return}let read = await log.load()+ guard let records = read.records else { throw CommandFailure((read.problem ?? .unreadable).summary) }if let problem = read.problem {Output.note(problem.summary)}- let removals = Array(RefusalRecord.grouped(read.records).prefix(limit))+ let removals = Array(RefusalRecord.grouped(records).prefix(limit))if output.json {try Output.json(removals.map { removal indiff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swiftindex e532e641..57bf3bf7 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift@@ -52,11 +52,10 @@ public actor RefusalLog {self.url = url}- public func load() -> (records: [RefusalRecord], problem: RefusalLogProblem?) {- FileLock.whileHeld(beside: url) {- let read = current()- return (read.records ?? [], read.problem)- }+ /// The records, with what went wrong reading them. Nil records when the file could not be read: what was refused+ /// is then not known, which is not the same as nothing refused.+ public func load() -> (records: [RefusalRecord]?, problem: RefusalLogProblem?) {+ FileLock.whileHeld(beside: url) { current() }}/// Writes down what one removal refused, and says what kept it from being written. The parts of one passdiff --git a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swiftindex a127eadc..7016751f 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift@@ -61,7 +61,7 @@ struct CleanupTests {}}#expect(FileManager.default.fileExists(atPath: cache.path(percentEncoded: false)))- #expect(await refusals.load().records.isEmpty)+ #expect(await refusals.load().records?.isEmpty == true)}/// While History cannot be read nothing moves, and the command says so above the list, with the way out.@@ -134,7 +134,7 @@ struct CleanupTests {#expect(!FileManager.default.fileExists(atPath: cache.path(percentEncoded: false)))#expect(records.map(\.originalURL) == [cache])#expect(records.allSatisfy { $0.source == "Editor" && $0.tool == "developer" && $0.size == 20 })- #expect(await RefusalLog(url: refusals.url).load().records.isEmpty)+ #expect(await RefusalLog(url: refusals.url).load().records?.isEmpty == true)}/// A removal that could not finish exits 1, and every item that stayed is recorded as refused.@@ -153,7 +153,7 @@ struct CleanupTests {}#expect(await RemovalLog(url: log.url).load().records?.isEmpty == true)- #expect(await RefusalLog(url: refusals.url).load().records.map(\.reason) == ["changed-since-scan"])+ #expect(await RefusalLog(url: refusals.url).load().records?.map(\.reason) == ["changed-since-scan"])#expect(FileManager.default.fileExists(atPath: cache.path(percentEncoded: false)))}@@ -175,7 +175,7 @@ struct CleanupTests {}#expect(await RemovalLog(url: log.url).load().records?.isEmpty == true)- #expect(await RefusalLog(url: refusals.url).load().records.map(\.reason) == ["stays-in-place"])+ #expect(await RefusalLog(url: refusals.url).load().records?.map(\.reason) == ["stays-in-place"])#expect(FileManager.default.fileExists(atPath: documents.path(percentEncoded: false)))}@@ -203,7 +203,7 @@ struct CleanupTests {try await plan.run(question: "?", dryRun: true, yes: true, using: try service(in: directory), refusals: refusals)- #expect(await RefusalLog(url: refusals.url).load().records.isEmpty)+ #expect(await RefusalLog(url: refusals.url).load().records?.isEmpty == true)}/// A refusal known before the move is shown in the plan, and is still recorded when the other items move.@@ -221,7 +221,7 @@ struct CleanupTests {try await plan.run(question: "?", dryRun: false, yes: true, using: service, recordingIn: log, refusals: refusals)#expect(await RemovalLog(url: log.url).load().records?.map(\.originalURL) == [cache])- #expect(await RefusalLog(url: refusals.url).load().records.map(\.url) == [documents])+ #expect(await RefusalLog(url: refusals.url).load().records?.map(\.url) == [documents])}/// `peel uninstall` writes down what the guard refused before the move beside what moved, as every other@@ -244,12 +244,12 @@ struct CleanupTests {let moved = await RemovalLog(url: log.url).load().records?.map(\.originalURL.lastPathComponent)#expect(Set(moved ?? []) == ["Editor.app", "blob"])- #expect(await RefusalLog(url: refusals.url).load().records.map(\.url) == [documents])+ #expect(await RefusalLog(url: refusals.url).load().records?.map(\.url) == [documents])let kept = UninstallPlan(app: documents, items: [UninstallPlan.Item(url: documents, size: nil, refusal: service.refusal(of: documents)),], needsAdministrator: 0, needsReview: 0)#expect(await kept.record(TrashResult(), from: "Documents", in: log, refusals: refusals))- #expect(await RefusalLog(url: refusals.url).load().records.map(\.url) == [documents, documents])+ #expect(await RefusalLog(url: refusals.url).load().records?.map(\.url) == [documents, documents])}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swiftindex bb65c8c5..c8d27d43 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift@@ -291,7 +291,7 @@ struct FileCommandTests {}#expect(await moved(logs).isEmpty)- #expect(await logs.refusals.load().records.map(\.reason) == ["needs-helper"])+ #expect(await logs.refusals.load().records?.map(\.reason) == ["needs-helper"])#expect(FileManager.default.fileExists(atPath: group.items[0].url.path(percentEncoded: false)))}@@ -312,7 +312,7 @@ struct FileCommandTests {}#expect(await moved(logs).isEmpty)- #expect(await logs.refusals.load().records.isEmpty)+ #expect(await logs.refusals.load().records?.isEmpty == true)#expect(FileManager.default.fileExists(atPath: group.items[0].url.path(percentEncoded: false)))#expect(collected.notes == "\(Output.path(group.items[0].url)) stays: holds a photo, music, or video library\n")}@@ -335,7 +335,7 @@ struct FileCommandTests {}#expect(await moved(logs) == ["com.example.gone"])- #expect(await logs.refusals.load().records.isEmpty)+ #expect(await logs.refusals.load().records?.isEmpty == true)#expect(FileManager.default.fileExists(atPath: group.items[1].url.path(percentEncoded: false)))#expect(collected.notes == "\(Output.path(group.items[1].url)) stays: holds a wallet or a signing key\n")}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swiftindex 31066ccb..b66956ec 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift@@ -286,7 +286,7 @@ struct HistoryCommandTests {try await (command(["history", "--refused", "--clear"]) as HistoryCommand).run(in: logs.removals, refusals: logs.refusals)- #expect(await logs.refusals.load().records.isEmpty)+ #expect(await logs.refusals.load().records?.isEmpty == true)}/// A History file that cannot be read is reported as an error, never shown as an empty History.@@ -305,6 +305,15 @@ struct HistoryCommandTests {}}+ @Test func refusesToListRefusalsItCannotRead() async throws {+ let directory = try TemporaryDirectory()+ let logs = logs(in: directory)+ try directory.file("Peel/refusals.json/kept.txt")++ await #expect(throws: CommandFailure.self) { try await printed(["history", "--refused"], from: logs) }+ await #expect(throws: CommandFailure.self) { try await printed(["history", "--refused", "--json"], from: logs) }+ }+@Test func putsNothingBackWhileTheExclusionsCannotBeRead() async throws {let directory = try TemporaryDirectory()let logs = logs(in: directory)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swiftindex 06a9779d..4bba9522 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift@@ -21,7 +21,7 @@ struct RefusalLogTests {tool: "applications")- let records = await RefusalLog(url: log.url).load().records+ let records = try #require(await RefusalLog(url: log.url).load().records)#expect(records.count == 2)#expect(records.allSatisfy { $0.source == "Editor" && $0.tool == "applications" })#expect(Set(records.map(\.reason)) == ["protected-place", "failed"])@@ -40,7 +40,7 @@ struct RefusalLogTests {#expect(await Removals.record(result, from: "Editor", sizes: [:], tool: "applications", in: log, refusals: refusals))#expect(await RemovalLog(url: log.url).load().records?.isEmpty == true)- #expect(await RefusalLog(url: refusals.url).load().records.map(\.reason) == ["protected-place"])+ #expect(await RefusalLog(url: refusals.url).load().records?.map(\.reason) == ["protected-place"])}/// History is the way back for what just moved, so it is written before the refusals: while the refusal log@@ -100,7 +100,7 @@ struct RefusalLogTests {await log.add(older, source: "Older", tool: "duplicates", date: .now.addingTimeInterval(-60))await log.add([failure("/Users/me/new", .notPermitted)], source: "New", tool: "space")- let records = await log.load().records+ let records = try #require(await log.load().records)#expect(records.count == 2_001)#expect(Set(records.map(\.source)) == ["Older", "New"])}@@ -117,7 +117,7 @@ struct RefusalLogTests {let outcome = await RefusalLog(url: url).load()- #expect(outcome.records.map(\.reason) == ["last-copy"])+ #expect(outcome.records?.map(\.reason) == ["last-copy"])guard case .damaged(let setAside) = outcome.problem else { Issue.record("no damage reported"); return }#expect(setAside.lastPathComponent.contains("damaged"))#expect(try FileManager.default.contentsOfDirectory(atPath: url.deletingLastPathComponent().path(percentEncoded: false))@@ -139,7 +139,7 @@ struct RefusalLogTests {try FileManager.default.setAttributes([.posixPermissions: 0o644], ofItemAtPath: url.path(percentEncoded: false))#expect(try Data(contentsOf: url) == Data("[]".utf8), "an unreadable record was written over")#expect(problem == .unreadable)- #expect(outcome.problem == .unreadable && outcome.records.isEmpty)+ #expect(outcome.problem == .unreadable && outcome.records == nil)}/// A refusal that could not be written down is said, rather than lost without a word.@@ -172,7 +172,7 @@ struct RefusalLogTests {await log.add([failure("/Users/me/a", .lastCopy)], source: "Editor", tool: "applications")#expect(await log.clear())- #expect(await log.load().records.isEmpty)+ #expect(await log.load().records?.isEmpty == true)#expect(await log.clear(), "forgetting what is already forgotten is no failure")}@@ -224,7 +224,7 @@ struct RefusalLogTests {await log.add([failure("/Users/me/a", .lastCopy), failure("/Users/me/b", .lastCopy)], source: "Duplicates", sourceKey: "tool", tool: "duplicates")await log.add([failure("/Users/me/c", .notPermitted)], source: "Editor", tool: "applications")- let records = await log.load().records+ let records = try #require(await log.load().records)let first = records.filter { $0.source == "Duplicates" }#expect(first.count == 2)#expect(Set(first.map(\.batch)).count == 1)@@ -266,7 +266,7 @@ struct RefusalLogTests {try Data(stored.utf8).write(to: url)await RefusalLog(url: url).add([failure("/Users/me/new", .notPermitted)], source: "Editor", tool: "applications")- let records = await RefusalLog(url: url).load().records+ let records = try #require(await RefusalLog(url: url).load().records)#expect(records.count == 4)#expect(RefusalRecord.grouped(records).first { $0.id == batch }?.parts.map(\.tool) == ["orphans", "duplicates"])diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swiftindex 8e6022b0..f143c5e5 100644--- a/Peel/Model/RemovalHistoryStore.swift+++ b/Peel/Model/RemovalHistoryStore.swift@@ -166,7 +166,7 @@ final class RemovalHistoryStore {refusalProblem = read.problemrefusalChange += 1let change = refusalChange- let listed = await Self.listed(read.records)+ let listed = await Self.listed(read.records ?? [])guard change == refusalChange else { return }refusalBatches = listed.batchesrefusalSearchKeys = listed.searchKeys