diff options
Diffstat (limited to 'src/dump.zig')
| -rw-r--r-- | src/dump.zig | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/dump.zig b/src/dump.zig index 971a4d26..c5e2953b 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -263,11 +263,15 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 { pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) ![]u8 { slim_terminals = true; defer slim_terminals = false; + join_files = true; + defer join_files = false; return dumpWith(p, deferred); } /// `dumpJoin`'s and `dumpExit`'s: a terminal dumps its size, not its emulator. pub var slim_terminals = false; +/// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file). +var join_files = false; fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 { var d = try Session.init(p.gpa); @@ -782,6 +786,9 @@ const SlotRecord = struct { selection: []const u8 = "", /// A plain kind's block's hash (Kind.Slot.state). state: u64 = 0, + /// A client's join (`dumpJoin`): a plain kind's file, as the disk has + /// it now, which the client opens the pane from (plainHere). + file: ?[]const u8 = null, }; pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) !void { @@ -795,6 +802,15 @@ pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) owned = if (s.plain) |b| (if (b.len > 0) try s.gpa.dupe(u8, b) else null) else try slotRecord(@constCast(s)); r.record = owned; } + // Paid only at a client's join: the session keeps no file's bytes. + var file: ?[]u8 = null; + defer if (file) |f| s.gpa.free(f); + if (join_files and s.plain != null and s.ops != null) if (filesystem.localPath(s.path)) |path| { + const z = try s.gpa.dupeSentinel(u8, path, 0); + defer s.gpa.free(z); + file = filesystem.readHost(s.gpa, z, pardes.memory.limits.max_file_bytes) catch null; + r.file = file; + }; const bytes = try walk.save(SlotRecord, gpa, &r); defer gpa.free(bytes); try w.writeAll(bytes); @@ -830,6 +846,7 @@ pub fn slotRead(out: *Kind.Slot, gpa: std.mem.Allocator, bytes: []const u8) !voi out.values.set(r.values); out.selection = try gpa.dupe(u8, r.selection); if (r.record) |rec| out.record = try gpa.dupe(u8, rec); + if (r.file) |f| out.file = try gpa.dupe(u8, f); } pub fn slotFree(s: *Kind.Slot, gpa: std.mem.Allocator) void { @@ -883,7 +900,7 @@ pub fn plainHere(p: *Pardes, id: usize, old: *Kind.Slot, ops: *const Kind.Ops) ! s.path = try p.gpa.dupe(u8, old.path); s.selection = try p.gpa.dupe(u8, old.selection); const kept = .{ old.next_tick, old.views, old.focused, old.state }; - if (!Kind.reopen(p, id, s, null)) return error.KindRefused; + if (!Kind.reopen(p, id, s, old.file)) return error.KindRefused; // Its block the session's, byte for byte (its record), never through // the kind's load, which may tidy it. const block = s.plain orelse return error.KindRefused; |
