summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 15:39:26 -0300
committerGabriel Schneider <[email protected]>2026-11-05 19:16:37 -0300
commitcd712084c68b9e2bad350066a92a96ce78a9ff35 (patch)
treee7dee186af5e761450f0b8b0f1bce24802e3babf /src/dump.zig
parent1eae252b80ddab0a06574de700b6b2957d3b64fc (diff)
downloadpardes-cd712084c68b9e2bad350066a92a96ce78a9ff35.tar.gz
pardes-cd712084c68b9e2bad350066a92a96ce78a9ff35.zip
migration: a state file that holds no Recent yet reads it once from the files before it, 0.24's $XDG_STATE_HOME/pardes/recent (merged as another session's commit is), else the `store` before that (its `@r` records, the oldest first, as W4's one-time read did), and leaves both where they are (Options.recent_import names their directory, set by main.zig alone, so no test reads the user's); an old `.dump` file, the byte dump, stays readable for one release: `-l <path>` and `Restore <path>` read it, told from an image by its first bytes rather than by its name (the snapshot and process harnesses' dumps are `.dump.zon` files, and a renamed file is the same file), and an Upgrade from the build before, whose record names its `.dump` file and no label, loads it and deletes it as before, so the next Upgrade commits to the state file; tests: Db.zig's 'Recent is read once from the file it replaced, else from the store before that, both left where they are' (in place of W4's 'the store Recent's file replaced is read once, its newest records first, over the file's list'), dump.zig's 'an old dump's file, a byte dump, is read by -l and by a Restore of its path, for one release', and upgrade.zig's 'an upgrade from the build before reads the dump file its record names, and deletes it once loaded'
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/dump.zig')
-rw-r--r--src/dump.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/dump.zig b/src/dump.zig
index 8847152d..facd9b9a 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -853,3 +853,34 @@ test "a session's byte dump read by name, field by field as another build reads
try std.testing.expectEqualStrings("", l.notes.items);
try std.testing.expectEqual(walk.digest(Pardes, p), walk.digest(Pardes, q));
}
+
+test "an old dump's file, a byte dump, is read by -l and by a Restore of its path, for one release" {
+ const gpa = std.testing.allocator;
+ const th = @import("ninep/testing.zig");
+ const p = try Pardes.init(gpa, .{ .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("kept in a .dump\n");
+ const bytes = try byteDump(p);
+ defer gpa.free(bytes);
+ try std.testing.expect(std.mem.startsWith(u8, bytes, "pardes-dump"));
+ // -l: the file read whole, and loaded.
+ const q = try initFromDump(gpa, .{ .tty_only = true }, bytes);
+ defer q.deinit();
+ const text = for (q.panes) |slot| {
+ if (slot) |pane| if (pane.file) |f| if (f.output == null) break f.content;
+ } else return error.FileLost;
+ try std.testing.expectEqualStrings("kept in a .dump\n", text);
+ // Restore of its path, as a word in a tag or a script gives it.
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "old.dump", .data = bytes });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ var line: [4200]u8 = undefined;
+ const answer = th.wr(q, @backingInt(ctlfs.TopFile.ctl), try std.fmt.bufPrint(&line, "Restore {s}/old.dump\n", .{dir}));
+ try std.testing.expectEqual(ctlfs.Status.ok, answer.reply.status);
+ const name = q.takeRestore().?;
+ const again = try restoreBytes(q, gpa, name);
+ defer gpa.free(again);
+ try std.testing.expectEqualSlices(u8, bytes, again);
+}