summaryrefslogtreecommitdiff
path: root/src/host_io.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/host_io.zig')
-rw-r--r--src/host_io.zig31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/host_io.zig b/src/host_io.zig
index 0c638f71..1a328ad5 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -106,7 +106,7 @@ pub fn stopWorkers() void {
/// window): the others are let go, as a detach of each.
pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u8, peers: *replica.Peers, inotify_fd: c_int, watches: *file_watch.Table) ?*pardes.Pardes {
peers.dropAll(core);
- const bytes = filesystem.readRestore(gpa, path, core.settings.dump_dir.get()) catch |err| {
+ const bytes = pardes.dump.restoreBytes(core, gpa, path) catch |err| {
core.reportError(core.active, "Restore", err);
return null;
};
@@ -3509,12 +3509,31 @@ pub fn writeFile(core: *pardes.Pardes, watches: *file_watch.Table, pane: u8, pat
pardes.exec.reapplyInitFile(core, path, bytes);
}
-/// A Dump's write, into the DumpDir.
+/// A Dump's write: into the state file under a label of its own
+/// (Db.putDump), or as a file of its own where `Dump export` names one or
+/// $PARDES_DUMP does (verbatim: the snapshot harness pins it for its
+/// goldens).
pub fn writeDump(core: *pardes.Pardes, bytes: []const u8) void {
- var pbuf: [1024:0]u8 = undefined;
- const path = pardes.dump.outPath(&pbuf, core.settings.dump_dir.get()) orelse return core.dumpFailed(core.settings.dump_dir.get(), error.NoDumpDirectory);
- filesystem.write(core, path, bytes) catch |err| return core.dumpFailed(path, err);
- core.setLastDump(path);
+ const to: ?[]const u8 = core.dump_export orelse if (std.c.getenv("PARDES_DUMP")) |p| std.mem.span(p) else null;
+ if (to) |path| {
+ filesystem.write(core, path, bytes) catch |err| return core.dumpFailed(path, err);
+ return core.setLastDump(path);
+ }
+ var stamp: [64]u8 = undefined;
+ var buf: [128]u8 = undefined;
+ const label = core.db.putDump(core, bytes, pardes.dump.label(&stamp), &buf) catch |err| {
+ var path: [4200]u8 = undefined;
+ // In the words a host reports failures in (tape.Failure).
+ const said: pardes.tape.Failure = switch (err) {
+ error.NoStateFile => error.NoDumpDirectory,
+ error.OutOfMemory => error.OutOfMemory,
+ error.NoSpaceLeft => error.NoSpaceLeft,
+ error.AccessDenied => error.AccessDenied,
+ else => error.InputOutput,
+ };
+ return core.dumpFailed(pardes.Db.statePath(&path, core.settings.dump_dir.get()) orelse core.settings.dump_dir.get(), said);
+ };
+ core.setLastDump(label);
}
/// DumpThemes: the built-in themes written below the config directory.