17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/brute/tools/fs_undo.rb', line 17
def call(path:)
target = File.expand_path(path)
Brute::FileMutationQueue.serialize(target) do
snapshot = Brute::SnapshotStore.pop(target)
raise "No undo history available for: #{target}" unless snapshot
if snapshot == :did_not_exist
File.delete(target) if File.exist?(target)
{success: true, action: "deleted (file did not exist before)"}
else
File.write(target, snapshot)
{success: true, action: "restored", bytes: snapshot.bytesize}
end
end
end
|