From 90530f893236c665deb9f5bddc925ee1fe51cca5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 28 Sep 2026 23:13:57 -0300 Subject: A failed Dump or a Restore of no dump fails its write, before any warning A Dump into a DumpDir it could not write, or a Restore of a file that is not a dump, answered a ctl write with rc 0 and only a message, and the Restore warned about unsaved panes before it ever looked at the file. The hosts' dump write now fails the waiting 9P write with EIO (the late failure a Save uses), naming the path and the reason in the log, and Restore parses the file before its unsaved-panes refusal, failing with `not a pardes dump`. Co-Authored-By: Claude Opus 5.5 --- src/dump.zig | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/dump.zig') diff --git a/src/dump.zig b/src/dump.zig index ef442ddb..5ebb3c8d 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -305,6 +305,15 @@ pub const Parsed = struct { } }; +/// Whether `bytes` are a dump a Restore could load, saying nothing: a +/// Restore asks before it warns about unsaved text or replaces anything. +pub fn check(gpa: std.mem.Allocator, bytes: []const u8) !void { + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const source = try arena.allocator().dupeZ(u8, bytes); + try validate(try std.zon.parse.fromSliceAlloc(State, arena.allocator(), source, null, .{ .free_on_error = false })); +} + pub fn readZon(gpa: std.mem.Allocator, bytes: []const u8, label: []const u8) !Parsed { var parsed: Parsed = .{ .value = undefined, .arena = .init(gpa) }; errdefer parsed.deinit(); -- cgit v1.3