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.

peel restore asks for the disk an item waits on

Țugui Dragoș138076ea58f5
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
index 3523abb7..ec92ea66 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
@@ -297,14 +297,26 @@ struct RestoreCommand: AsyncParsableCommand {
}
let batch = try Self.batch(matching: id, in: Batch.all(in: records))
let going = batch.restorable
+ // An item in the Trash of a disk that isn't connected is still there, once the disk is.
+ let waiting = batch.records.filter { !$0.isStillInTrash && !$0.isOnAConnectedDisk }
+ let items = Output.count(waiting.count, "item is", "items are")
+ let elsewhere = waiting.isEmpty
+ ? nil
+ : "\(items) on a disk that isn't connected. Connect it and run the command again."
guard !going.isEmpty else {
- throw CommandFailure("Nothing of that removal is in the Trash anymore, so there is nothing to put back.")
+ let nothing = "Nothing of that removal is in the Trash anymore, so there is nothing to put back."
+ throw CommandFailure(elsewhere ?? nothing)
}
Output.table(going.map { [Output.size($0.size), Output.path($0.originalURL)] })
Output.line("Total: \(Output.size(going.totalSize))")
- if going.count < batch.records.count {
- Output.note("\(Output.count(batch.records.count - going.count, "item is", "items are")) no longer in the Trash and will stay as they are.")
+ let gone = batch.records.count - going.count - waiting.count
+ if gone > 0 {
+ let items = Output.count(gone, "item is", "items are")
+ Output.note("\(items) no longer in the Trash and will stay as they are.")
+ }
+ if let elsewhere {
+ Output.note(elsewhere)
}
guard !dryRun else {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift
index 7cc7ad75..194a919e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift
@@ -325,6 +325,30 @@ struct HistoryCommandTests {
}
}
+ /// An item in the Trash of a disk that isn't connected is still there to put back, so the command asks for the
+ /// disk rather than say nothing is left.
+ @Test func asksForTheDiskAnItemWaitsOn() async throws {
+ let directory = try TemporaryDirectory()
+ let logs = logs(in: directory)
+ let record = RemovalRecord(
+ batch: UUID(),
+ item: TrashedItem(
+ originalURL: URL(filePath: "/Volumes/org.example.Missing/Report.pdf"),
+ trashedURL: URL(filePath: "/Volumes/org.example.Missing/.Trashes/501/Report.pdf"),
+ date: .now
+ ),
+ size: 10, source: "Editor", tool: "applications"
+ )
+ _ = await logs.removals.add([record])
+
+ let failure = await #expect(throws: CommandFailure.self) {
+ try await (command(["restore", String(record.batch.uuidString.prefix(8)), "-y"]) as RestoreCommand)
+ .run(in: logs.removals, using: service(in: directory))
+ }
+ let asked = "1 item is on a disk that isn't connected. Connect it and run the command again."
+ #expect(failure?.description == asked)
+ }
+
@Test func aDryRunPutsNothingBack() async throws {
let directory = try TemporaryDirectory()
let logs = logs(in: directory)