summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
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);
+}