Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Say each item stays on a dry run while the exclusions can't be read

Țugui Dragoș16444a8a070e
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
index 44d60328..981d98d5 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
@@ -39,10 +39,7 @@ struct Cleanup {
Item(
url: $0.url,
size: $0.size,
- // While the exclusions can't be read the guard refuses everything, which says nothing of the
- // item itself: `run` then moves nothing and names the list.
- refusal: needingAdministrator.contains($0.url)
- ? .needsHelper : service.knowsTheExclusions ? service.refusal(of: $0.url) : nil
+ refusal: needingAdministrator.contains($0.url) ? .needsHelper : service.refusal(of: $0.url)
)
},
source: source,
@@ -77,7 +74,9 @@ struct Cleanup {
Output.table(items.map { item in
[Output.size(item.size), Output.path(item.url)] + (saysWhyItStays ? [item.refusal.map { "stays: \($0.summary)" } ?? "moves"] : [])
})
- Output.line("Total: \(Output.size(total))")
+ if !moving.isEmpty {
+ Output.line("Total: \(Output.size(total))")
+ }
notes.forEach(Output.note)
let tooMany = Self.tooMany(moving.map(\.url))
@@ -86,6 +85,7 @@ struct Cleanup {
Output.line(moving.isEmpty ? "Nothing here can be moved." : "Dry run: nothing was moved.")
return
}
+ // The guard then refuses everything, which says nothing of the items, so no refusal is recorded.
guard service.knowsTheExclusions else {
throw AppLookup.Failure.exclusionsUnreadable(ExclusionStore.defaultURL.path(percentEncoded: false))
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift
index 0d2e4cb0..c23e9497 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift
@@ -86,7 +86,6 @@ struct CleanupTests {
let removals = RemovalLog(url: directory.url.appending(path: "Peel/removals.json"))
let plan = cleanup(items: [(cache, 20)], service: service)
- #expect(plan.items.allSatisfy { $0.refusal == nil })
await #expect(throws: AppLookup.Failure.self) {
try await Output.$collected.withValue(Output.Collected()) {
try await plan.run(
@@ -99,6 +98,24 @@ struct CleanupTests {
#expect(await refusals.load().records?.isEmpty == true)
}
+ @Test func aDryRunSaysEachItemStaysWhileTheExclusionsCannotBeRead() async throws {
+ let directory = try TemporaryDirectory()
+ let cache = try directory.file("home/Library/Caches/com.example.editor/blob", bytes: 20)
+ let service = try service(in: directory, exclusions: .unreadable)
+ let removals = RemovalLog(url: directory.url.appending(path: "Peel/removals.json"))
+ let collected = Output.Collected()
+
+ try await Output.$collected.withValue(collected) {
+ try await cleanup(items: [(cache, 20)], service: service)
+ .run(question: "?", dryRun: true, yes: true, using: service, recordingIn: removals)
+ }
+
+ #expect(collected.output.contains("stays: your exclusions couldn't be read"))
+ #expect(collected.output.contains("Nothing here can be moved."))
+ #expect(!collected.output.contains("Total:"))
+ #expect(!collected.output.contains("Dry run"))
+ }
+
/// While History cannot be read nothing moves, and the command says so above the list, with the way out.
@Test(.permissionsHold) func saysSoWhenHistoryCannotBeRead() async throws {
let directory = try TemporaryDirectory()