summaryrefslogtreecommitdiff
path: root/core/dump.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 11:42:48 -0300
committerGabriel Schneider <[email protected]>2026-11-19 11:42:48 -0300
commit71d8744b41dec56d835e30f531b96fede5d610a1 (patch)
tree31e2a06fdcfd467d12454cde8be5a477765701b5 /core/dump.zig
parenteae5736ad923731135dd35b3783c90a3358bd0fa (diff)
parent4569aefd55d04f434f2e2ed5e6e4a511a414cdc7 (diff)
downloadpardes-71d8744b41dec56d835e30f531b96fede5d610a1.tar.gz
pardes-71d8744b41dec56d835e30f531b96fede5d610a1.zip
integration: the one client loop that the soak runs, with the tape as the handle a step is given: pardes-runners-b (10b: runtime/client.zig run by the terminal's client, the window's and the soak; a client's clipboard and links its own frontend's; an input sent before it is applied) and pardes-handle-1 (the handle's steps 0 to 2: p.tape, the directory listing and the file system read through the tape they are handed), merged without a conflict; gates in the coordinator's ledger
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/dump.zig')
-rw-r--r--core/dump.zig52
1 files changed, 27 insertions, 25 deletions
diff --git a/core/dump.zig b/core/dump.zig
index d8d87fc6..e6e13a64 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -43,12 +43,12 @@ fn hostEnv(name: [*:0]const u8) ?[*:0]u8 {
/// Where the state file is (Db.zig) and relative Restore names are looked
/// up: the `DumpDir` setting when set (a leading `~/` is the home
/// directory), else the default.
-pub fn directory(buf: []u8, dir_setting: []const u8) ?[]const u8 {
+pub fn directory(tape: *pardes.tape.Tape, buf: []u8, dir_setting: []const u8) ?[]const u8 {
if (dir_setting.len == 0) return defaultDirectory(buf);
var joined: [4096]u8 = undefined;
// `~/x`, else a relative one from the directory pardes started in: the
// same place however it was written, and shown so.
- const raw = pardes.filesystem.expandHome(dir_setting, &joined);
+ const raw = pardes.filesystem.expandHome(tape, dir_setting, &joined);
var fba_buf: [4096]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&fba_buf);
var cwd_buf: [1024]u8 = undefined;
@@ -98,11 +98,11 @@ const Session = walk.Dump(&.{ Pardes, []const filesystem.Mount, OnDisk, []const
const SessionLoad = walk.Load(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Shares });
const OnDisk = [MAX_PANES]bool;
-fn onDisk(pane: *const pardes.panes.Pane) bool {
+fn onDisk(tape: *pardes.tape.Tape, pane: *const pardes.panes.Pane) bool {
const f = pane.file orelse return false;
if (f.output != null) return false;
const local = filesystem.localPath(f.path) orelse return false;
- return exec.kindOf(local) != null;
+ return exec.kindOf(tape, local) != null;
}
pub fn dumpState(p: *Pardes) !void {
@@ -177,8 +177,8 @@ pub fn dumpTo(p: *Pardes, to: ?[]const u8) !void {
/// with a `/` or `~/` (as it resolves, else as typed: the read says why),
/// or a bare word that names a file in the DumpDir or the directory pardes
/// runs in; null for one that names none: a label of the state file's.
-pub fn restoreFile(name: []const u8, dir_setting: []const u8, out: *[4096]u8) ?[]const u8 {
- const path = filesystem.restorePath(name, dir_setting, out);
+pub fn restoreFile(tape: *pardes.tape.Tape, name: []const u8, dir_setting: []const u8, out: *[4096]u8) ?[]const u8 {
+ const path = filesystem.restorePath(tape, name, dir_setting, out);
if (std.mem.indexOfScalar(u8, name, '/') != null or std.mem.startsWith(u8, name, "~")) return path;
return if (std.Io.Dir.path.isAbsolute(path)) path else null;
}
@@ -187,7 +187,7 @@ pub fn restoreFile(name: []const u8, dir_setting: []const u8, out: *[4096]u8) ?[
/// or an old byte dump), else the state file's dump of that label.
pub fn restoreBytes(p: *Pardes, gpa: std.mem.Allocator, name: []const u8) ![]u8 {
var buf: [4096]u8 = undefined;
- if (restoreFile(name, p.settings.dump_dir.get(), &buf)) |path| return filesystem.readFile(gpa, path);
+ if (restoreFile(p.tape, name, p.settings.dump_dir.get(), &buf)) |path| return filesystem.readFile(p.tape, gpa, path);
const got = p.db.getDump(p, gpa, name) catch |err| return if (err == error.OutOfMemory) error.OutOfMemory else error.BadDump;
return got orelse error.FileNotFound;
}
@@ -222,7 +222,7 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 {
var names: std.Io.Writer.Allocating = .init(gpa);
defer names.deinit();
for (p.panes, &on_disk) |slot, *on| if (slot) |pane| {
- on.* = onDisk(pane);
+ on.* = onDisk(p.tape, pane);
panes += 1;
const shown: []const u8 = if (pane.addon) |k| k.path else if (pane.file) |f| (if (f.output == null) f.path else "") else pane.cwdSlice();
if (shown.len == 0 or names.written().len + shown.len > 4096) continue;
@@ -263,15 +263,18 @@ 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;
+ // The join's file reads are the session's host's, between its steps:
+ // with its io, which the core's tape holds (a walk's hook takes no more).
+ join_files = p.tape.io;
+ defer join_files = null;
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;
+/// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file),
+/// read with this io.
+var join_files: ?std.Io = null;
fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 {
var d = try Session.init(p.gpa);
@@ -282,7 +285,7 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8
try d.put([]const filesystem.Mount, &mounts);
var on_disk: OnDisk = @splat(false);
for (p.panes, &on_disk) |slot, *on| if (slot) |pane| {
- on.* = onDisk(pane);
+ on.* = onDisk(p.tape, pane);
};
try d.put(OnDisk, &on_disk);
const theme: []const u8 = colors.themes[@min(p.settings.theme, colors.themes.len - 1)].name;
@@ -536,12 +539,11 @@ pub fn restore(p: *Pardes, bytes: []const u8, from: []const u8) !*Pardes {
pub fn initFromDump(gpa: std.mem.Allocator, opts: Options, bytes: []const u8) !*Pardes {
pardes.tape.startFromEnv();
const taped = pardes.tape.enter(null, .{ .init_from_dump = .{ .opts = opts, .bytes = bytes } });
- const p = (if (Handover.carries(gpa, bytes)) carriedWindow(gpa, opts, bytes) else loadAndRevive(gpa, opts, bytes, null, null)) catch |err| {
- pardes.tape.leave(null, taped);
- return err;
- };
- pardes.tape.leave(p, taped);
- return p;
+ // The tape adopts the core made, none on a failure.
+ var made: ?*Pardes = null;
+ defer pardes.tape.leave(made, taped);
+ made = try (if (Handover.carries(gpa, bytes)) carriedWindow(gpa, opts, bytes) else loadAndRevive(gpa, opts, bytes, null, null));
+ return made.?;
}
/// A window of its own for panes a grip carried out of another (Handover):
@@ -692,7 +694,7 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool
// Its file gone from disk since the dump: its text is nowhere else, so
// it is said deleted, and Del, Exit and Restore ask first. One never on
// disk (a name not yet saved) comes back as it was.
- if (was_on_disk and !onDisk(pane)) pardes.panes.File.deleted(p, @intCast(id));
+ if (was_on_disk and !onDisk(p.tape, pane)) pardes.panes.File.deleted(p, @intCast(id));
}
// ---- one pane to and from a dump: the store's, a handover's ----
@@ -809,10 +811,10 @@ pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer)
// 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| {
+ if (join_files) |io| if (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;
+ file = filesystem.readHost(io, s.gpa, z, pardes.memory.limits.max_file_bytes) catch null;
r.file = file;
};
const bytes = try walk.save(SlotRecord, gpa, &r);
@@ -945,9 +947,9 @@ fn revivePdf(p: *Pardes, id: usize, pane: *pardes.panes.Pane, old: *pardes.panes
test "a DumpDir reads back absolute, however it was written" {
var buf: [4096]u8 = undefined;
- try std.testing.expectEqualStrings("/tmp/dumps", directory(&buf, "/tmp/dumps/").?);
- try std.testing.expectEqualStrings("/tmp/dumps", directory(&buf, "/tmp//x/../dumps").?);
- const rel = directory(&buf, "rel/");
+ try std.testing.expectEqualStrings("/tmp/dumps", directory(&pardes.tape.none, &buf, "/tmp/dumps/").?);
+ try std.testing.expectEqualStrings("/tmp/dumps", directory(&pardes.tape.none, &buf, "/tmp//x/../dumps").?);
+ const rel = directory(&pardes.tape.none, &buf, "rel/");
try std.testing.expect(std.Io.Dir.path.isAbsolute(rel.?) and std.mem.endsWith(u8, rel.?, "/rel"));
}