diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 12:40:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 14:56:36 -0300 |
| commit | 36a51ddc67d0beb7d9851fb2425cf780a47fed36 (patch) | |
| tree | d534d3151d836ea7a275e9f118a89f2bbc0d0448 /src/ninep/tree.zig | |
| parent | 4917ae452a15ff4f32d97d215a99fdcfaab29d61 (diff) | |
| download | pardes-36a51ddc67d0beb7d9851fb2425cf780a47fed36.tar.gz pardes-36a51ddc67d0beb7d9851fb2425cf780a47fed36.zip | |
idioms #10, the 9P tree: every bufPrint that fell back to "" or a placeholder is proven to fit (catch unreachable, its why) or cut its argument to fit, /status, /listeners and the 9P reads that staged on gpa answer ENOMEM rather than read short, acme's pane ctl words and pty's files and signals are stringToEnum switches, a dirent's head and name are staged together or not at all, a repeated log record too long to count is pushed as its own line rather than dropped, and daemonList's set is named
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep/tree.zig')
| -rw-r--r-- | src/ninep/tree.zig | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index d15ddd53..2117916d 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -453,12 +453,14 @@ pub fn stageDirent(out: *std.ArrayList(u8), gpa: std.mem.Allocator, node: u64, d std.mem.writeInt(u64, head[0..8], node, .little); head[8] = @intFromBool(dir); head[9] = @intCast(name.len); - out.appendSlice(gpa, &head) catch return; - out.appendSlice(gpa, name) catch return; + // Head and name both or neither: a head alone would corrupt the listing. + out.ensureUnusedCapacity(gpa, head.len + name.len) catch return; + out.appendSliceAssumeCapacity(&head); + out.appendSliceAssumeCapacity(name); } /// The daemon's registry (/sessions), its `list` answer as it gave it. -fn daemonList(gpa: std.mem.Allocator) anyerror![]u8 { +fn daemonList(gpa: std.mem.Allocator) error{ NoDaemon, OutOfMemory }![]u8 { var buf: [4096]u8 = undefined; const said = daemon.ask("list", &buf) orelse return error.NoDaemon; return gpa.dupe(u8, said); @@ -682,7 +684,7 @@ fn topSize(p: *Pardes, f: TopFile) u64 { .root, .pane, .col, .screen, .new, .layout, .index, .recent, .dumps, .addons, .listeners, .sessions, .kbdin, .mousein => 0, .tag => cols.headerText(p, null).?.len, .README => fs.help.len, - .status => ctl.statusText(p).len, + .status => if (ctl.statusText(p)) |text| text.len else |_| 0, .look, .exec, .tagexec, .pager => ctl.resultsLen(p), // A stream: a length would read as its end to a kernel that caches // one (a 9ns mount's splice), and a follower's reads go past it. @@ -836,7 +838,7 @@ fn open(p: *Pardes, req: Req, target: Target) Reply { // pane it made, so reading it twice answers the same one and // closing it leaves the pane alone. .new => { - const slot = p.freeSlot() orelse return failText(req.tag, E.NOSPC, std.fmt.bufPrint(&p.fs.ename, "pane/new: " ++ pardes.Messages.no_pane_slots, .{pardes.MAX_PANES}) catch "no space for a pane"); + const slot = p.freeSlot() orelse return failText(req.tag, E.NOSPC, std.fmt.bufPrint(&p.fs.ename, "pane/new: " ++ pardes.Messages.no_pane_slots, .{pardes.MAX_PANES}) catch unreachable); // short p.fs.no_pane_slot = false; // Refused, the open's err is the one record of it (the // one rule): no msg besides. @@ -1080,15 +1082,15 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply { // newline in it `\n` (events.shown). var name_buf: [4 * 4096]u8 = undefined; const name = events.shown(pane.nameOf(p, pn), &name_buf); - out.print(p.gpa, "{d} {s} {d} {s} {d}\n", .{ serial, pane.kindOf(pn), @intFromBool(pane.dirtyOf(pn)), name, pane.columnOf(p, id) }) catch {}; + out.print(p.gpa, "{d} {s} {d} {s} {d}\n", .{ serial, pane.kindOf(pn), @intFromBool(pane.dirtyOf(pn)), name, pane.columnOf(p, id) }) catch break :index Reply.fail(req.tag, E.NOMEM); } break :index stagedReply(p, req); }, - .status => window(p, req, ctl.statusText(p)), + .status => window(p, req, ctl.statusText(p) catch return Reply.fail(req.tag, E.NOMEM)), .look, .exec, .tagexec, .pager => ctl.readResults(p, req), .log => events.readLog(p, req), .screen => screen.readSnapshot(p, req, null), - .listeners => window(p, req, screen.listenersText(p)), + .listeners => window(p, req, screen.listenersText(p) catch return Reply.fail(req.tag, E.NOMEM)), .sessions => sessions: { if (comptime !daemon.supported) break :sessions stagedReply(p, req); // Out of the turn: the daemon answers within 2 s, or not at all. |
