summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 12:40:11 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commit36a51ddc67d0beb7d9851fb2425cf780a47fed36 (patch)
treed534d3151d836ea7a275e9f118a89f2bbc0d0448 /src/ninep
parent4917ae452a15ff4f32d97d215a99fdcfaab29d61 (diff)
downloadpardes-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')
-rw-r--r--src/ninep/cols.zig4
-rw-r--r--src/ninep/ctl.zig237
-rw-r--r--src/ninep/events.zig24
-rw-r--r--src/ninep/pane.zig18
-rw-r--r--src/ninep/pty.zig30
-rw-r--r--src/ninep/screen.zig8
-rw-r--r--src/ninep/sources.zig4
-rw-r--r--src/ninep/tree.zig18
8 files changed, 172 insertions, 171 deletions
diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig
index 74d1f668..7eb08ba9 100644
--- a/src/ninep/cols.zig
+++ b/src/ninep/cols.zig
@@ -31,7 +31,7 @@ pub fn activeColumn(p: *const Pardes) ?usize {
/// keyboard), `empty` or `full`, and its panes' serials, top to bottom;
/// then `active <serial>`: the active column, where pane/new and a look
/// place a pane next (acme's activecol), not always the keyboard's.
-pub fn writeLayout(p: *Pardes, w: *std.Io.Writer) !void {
+pub fn writeLayout(p: *Pardes, w: *std.Io.Writer) std.Io.Writer.Error!void {
const v = p.view();
const active = activeColumn(p);
for (0..p.view().ncol) |c| {
@@ -414,7 +414,7 @@ test "Help and Find at /tagexec act in the session's directory, not the keyboard
for ([_][]const u8{ "Help\n", "Find needle\n" }) |line| {
try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, line).reply.status);
const made = p.panes[p.view().active].?.file.?.path;
- try testing.expectEqualStrings(session, std.fs.path.dirname(made).?);
+ try testing.expectEqualStrings(session, std.Io.Dir.path.dirname(made).?);
}
}
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 53128c5e..08bad9c3 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -320,7 +320,7 @@ pub fn captured(p: *Pardes, req: Req, id: usize, exec: bool, text: []const u8, i
pub fn failedWrite(p: *Pardes, tag: u64) ?Reply {
if (p.fs.failure_len == 0) return null;
const failure = p.fs.failure[0..p.fs.failure_len];
- return tree.failText(tag, failureErrno(failure), std.fmt.bufPrint(&p.fs.ename, "{s}", .{failure}) catch failure);
+ return tree.failText(tag, failureErrno(failure), std.fmt.bufPrint(&p.fs.ename, "{s}", .{failure}) catch unreachable); // failure's 256 bytes fit ename's 320
}
/// The errno a builtin's failure answers with: ENOENT for what is not
@@ -382,16 +382,16 @@ pub fn readResults(p: *Pardes, req: Req) Reply {
// ---- /status ----
/// /status's text, in the step's scratch.
-pub fn statusText(p: *Pardes) []const u8 {
+pub fn statusText(p: *Pardes) std.Io.Writer.Error![]const u8 {
var w: std.Io.Writer.Allocating = .init(p.scratch.allocator());
var count: usize = 0;
for (p.panes) |slot| count += @intFromBool(slot != null);
const pid: u32 = @intCast(std.c.getpid());
- w.writer.print("pid {d}\nversion {s}\npanes {d}\n", .{ pid, pardes.version, count }) catch {};
+ try w.writer.print("pid {d}\nversion {s}\npanes {d}\n", .{ pid, pardes.version, count });
// Whether the pointer is over this window: what a grip let go past
// another window's edge asks of every window, to find the one it was
// let go over (Handover.zig), where no window may know another's place.
- if (p.view().frontend.windowed) w.writer.print("pointer {s}\n", .{if (p.view().pointer_inside) "in" else "out"}) catch {};
+ if (p.view().frontend.windowed) try w.writer.print("pointer {s}\n", .{if (p.view().pointer_inside) "in" else "out"});
return w.written();
}
@@ -418,7 +418,8 @@ pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "colla
/// whether Redo has one. Then pardes's own: rio's word for whether the
/// window has the keyboard, `current` or `notcurrent` (rio(4), wctl), and
/// a REPL's id.
-pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 {
+pub fn paneText(p: *Pardes, pane: *Pane, buf: *[pane_text_cap]u8) []const u8 {
+ // unreachable below: pane_text_cap counts every field at its widest.
var w = std.Io.Writer.fixed(buf);
w.print("{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} ", .{
pane.serial,
@@ -429,30 +430,30 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 {
@intFromBool(if (pane.file) |f| f.listing != null else false),
@intFromBool(pane_files.dirtyOf(pane)),
pane.cols,
- }) catch return w.buffered();
+ }) catch unreachable;
const font = p.settings.font.effective_name.get();
- writeQuoted(&w, if (font.len == 0) "default" else font) catch return w.buffered();
+ writeQuoted(&w, if (font.len == 0) "default" else font) catch unreachable;
// While a column's or the workspace's tag has the keyboard, no pane does.
const current = p.panes[p.view().active] == pane and p.view().header == null;
const f = pane_files.fileOf(pane);
const undo = if (f) |file| file.history.journal.done > 0 else false;
const redo = if (f) |file| file.history.journal.done < file.history.journal.steps.items.len else false;
- w.print(" {d:>11} {d:>11} {d:>11} {s} ", .{ config.tab_now, @intFromBool(undo), @intFromBool(redo), if (current) "current" else "notcurrent" }) catch {};
+ w.print(" {d:>11} {d:>11} {d:>11} {s} ", .{ config.tab_now, @intFromBool(undo), @intFromBool(redo), if (current) "current" else "notcurrent" }) catch unreachable;
// A terminal bound as a REPL ends with its id, `python-a`.
var idbuf: [48]u8 = undefined;
const id = exec_line.replId(&idbuf, pane);
- if (id.len > 0) w.print("{s} ", .{id}) catch {};
+ if (id.len > 0) w.print("{s} ", .{id}) catch unreachable;
// Then what its tag does not say: Collapse, and a kind's own fields (a
// PDF's PdfFit and PdfTint, in the words they take).
- if (pane.collapsed) w.writeAll("collapsed ") catch {};
+ if (pane.collapsed) w.writeAll("collapsed ") catch unreachable;
if (pane.addon != null) {
var fields: [128]u8 = undefined;
const kind_fields = pardes.Kind.ctlRead(pane, &fields);
- if (kind_fields.len > 0) w.print("{s} ", .{kind_fields}) catch {};
+ if (kind_fields.len > 0) w.print("{s} ", .{kind_fields}) catch unreachable;
}
// Last, the body's mode, which the tag shows as a box: helix's select
// is normal mode extending.
- w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch {};
+ w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch unreachable;
return w.buffered();
}
@@ -521,7 +522,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
// acme's words: checked as the pardes word they run as, or refused.
const word = for (pardes.exec.acme_words) |w| {
if (!std.mem.eql(u8, typed, w.acme)) continue;
- const now = w.pardes orelse return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }) catch "invalid: an acme word pardes has not");
+ const now = w.pardes orelse return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }) catch unreachable); // acme_words holds short literals
break now;
} else typed;
const arg = if (sp) |s| std.mem.trim(u8, line[s + 1 ..], " \t") else "";
@@ -536,7 +537,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
var why: [64]u8 = undefined;
// EINVAL, a request this build cannot take, in words 9ns reads
// as that: `invalid`.
- return refuse(p, req, std.fmt.bufPrint(&why, "{s} is {s}, invalid here", .{ word, absent }) catch "GUI-only, invalid here", line);
+ return refuse(p, req, std.fmt.bufPrint(&why, "{s} is {s}, invalid here", .{ word, absent }) catch unreachable, line); // a known word (15 at most) and 17 fit 64
}
return refuse(p, req, "unknown control message", line);
};
@@ -560,7 +561,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
var near: [128]u8 = undefined;
const room = @import("cloud9").fs.errmax -| (head.len + tail.len + line.len + 3);
var why: [256]u8 = undefined;
- return refuse(p, req, std.fmt.bufPrint(&why, head ++ "{s}" ++ tail, .{pardes.colors.themesNear(near[0..@min(room, near.len)], arg)}) catch "bad value in control message", arg);
+ return refuse(p, req, std.fmt.bufPrint(&why, head ++ "{s}" ++ tail, .{pardes.colors.themesNear(near[0..@min(room, near.len)], arg)}) catch unreachable, arg); // 128 of names fit
},
.font => config.Runtime.FontSpec.parse(arg) != null,
// Bare, it says the width, as from a pane's exec.
@@ -572,11 +573,11 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
},
};
if (takes) return null;
- var why: [160]u8 = undefined;
+ var why: pardes.Kind.Buf(160) = .{};
// The offending word is the value: quoted, so two bad values read,
// and log, as two.
return refuseQuoting(p, req, if (config.Runtime.takes(setting.action)) |values|
- std.fmt.bufPrint(&why, "bad value in control message; takes {s}", .{values}) catch "bad value in control message"
+ why.print("bad value in control message; takes {s}", .{values})
else
"bad value in control message", arg, "");
}
@@ -643,7 +644,7 @@ fn writeSettingsFor(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer, cap
}
/// The root ctl's text (`writeSettings`), in the step's scratch.
-pub fn settingsText(p: *Pardes) ![]const u8 {
+pub fn settingsText(p: *Pardes) std.Io.Writer.Error![]const u8 {
var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
try writeSettings(p, &text.writer);
return text.written();
@@ -667,23 +668,23 @@ pub fn writePager(p: *Pardes, req: Req) Reply {
// directory it is, as any other pane's name is.
var home_buf: [4096]u8 = undefined;
const typed = pardes.filesystem.expandHome(std.mem.trim(u8, line, " \t"), &home_buf);
- const dir = if (typed.len > 0 and typed[0] == '/') std.fs.path.resolvePosix(p.scratch.allocator(), &.{typed}) catch typed else typed;
+ const dir = if (typed.len > 0 and typed[0] == '/') std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{typed}) catch typed else typed;
// A directory that is there, or none (the session's): never a +Pager
// named into one missing, nor a relative one quietly taken for none.
if (dir.len > 0 and dir[0] != '/') {
var shown: [256]u8 = undefined;
- return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "pager: invalid directory \"{s}\": must be absolute", .{blanked(dir[0..@min(dir.len, shown.len)], &shown)}) catch "pager: invalid directory: must be absolute");
+ return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "pager: invalid directory \"{s}\": must be absolute", .{blanked(dir[0..@min(dir.len, shown.len)], &shown)}) catch unreachable); // 256 fit 320
}
if (dir.len > 0) if (pardes.filesystem.localPath(dir)) |local| {
// A file there is no directory, ENOTDIR; nothing there, ENOENT.
if (exec_line.kindOf(local) != .directory) {
if (exec_line.kindOf(local) != null)
- return tree.failText(req.tag, E.NOTDIR, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: not a directory", .{dir[0..@min(dir.len, 256)]}) catch "pager: not a directory");
- return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch "pager: no such directory");
+ return tree.failText(req.tag, E.NOTDIR, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: not a directory", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320
+ return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320
}
// Nor one that may not be written, as a file's name there is refused.
if (pardes.filesystem.deniedAbove(local))
- return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch "pager: permission denied");
+ return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320
};
const id = pardes.panes.Output.openPager(p, p.view().active, dir) catch |err|
return tree.failText(req.tag, if (err == error.NoPaneRoom or err == error.NoPaneSlots) E.NOSPC else E.IO, switch (err) {
@@ -910,7 +911,7 @@ fn writeCommands(p: *const Pardes, w: *std.Io.Writer) !void {
}
/// /commands' text (`writeCommands`), in the step's scratch.
-pub fn commandsText(p: *Pardes) ![]const u8 {
+pub fn commandsText(p: *Pardes) std.Io.Writer.Error![]const u8 {
var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
try writeCommands(p, &text.writer);
return text.written();
@@ -1091,39 +1092,44 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
.refused => |r| return r,
.builtin => |word| line = word,
}
- if (std.mem.eql(u8, line, "get")) {
- if (!apply) continue;
- if (@import("../edit_cmd.zig").busyOn(p, p.paneBySerial(serial).?)) return tree.failText(req.tag, E.BUSY, "get: " ++ @import("../edit_cmd.zig").e_busy);
- // It ran and was refused: its words (in ename), not the line
- // quoted, as a builtin's refusal (Save's) says it.
- if (getRefused(p, pane, "get")) |said| return tree.failText(req.tag, E.IO, said);
- var failed: anyerror = error.Unexpected;
- const errno = get(p, pane, &failed);
- // Naming the path, in words 9ns reads as the errno; a peer
- // out of reach as a look or a Save says it.
- if (errno != 0) {
- const path = if (pane_files.fileOf(pane)) |f| f.path else "";
- var why_buf: [48]u8 = undefined;
- const why = if (pardes.Messages.dialReason(failed)) |r|
- std.fmt.bufPrint(&why_buf, "dial failed: {s}", .{r}) catch "dial failed"
- else if (errno == E.NOENT) "no such file" else "cannot be read";
- return tree.failText(req.tag, errno, std.fmt.bufPrint(&p.fs.ename, "get: {s}: {s}", .{ path[0..@min(path.len, 256)], why }) catch "get: no such file");
- }
- } else if (std.mem.eql(u8, line, "lock")) {
- if (mine == null) return tree.failText(req.tag, E.INVAL, tree.e_bad_ctl);
- if (other) return tree.failText(req.tag, E.BUSY, e_locked);
- held = true;
- if (apply) pane.fs.lock = mine;
- } else if (std.mem.eql(u8, line, "unlock")) {
- if (!held) return tree.failText(req.tag, E.INVAL, e_not_locked);
- held = false;
- if (apply) pane.fs.lock = null;
- } else if (std.mem.eql(u8, line, "answer")) {
- // With a question up, what it offers.
- var offered: [64]u8 = undefined;
- if (keys.questionChoices(p, p.paneBySerial(serial).?, &offered)) |choices|
- return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "answer takes {s} or -", .{choices}) catch "answer takes a choice or -");
- return tree.failText(req.tag, E.INVAL, "answer takes a choice or -");
+ if (std.meta.stringToEnum(enum { get, lock, unlock, answer }, line)) |word| switch (word) {
+ .get => {
+ if (!apply) continue;
+ if (@import("../edit_cmd.zig").busyOn(p, p.paneBySerial(serial).?)) return tree.failText(req.tag, E.BUSY, "get: " ++ @import("../edit_cmd.zig").e_busy);
+ // It ran and was refused: its words (in ename), not the line
+ // quoted, as a builtin's refusal (Save's) says it.
+ if (getRefused(p, pane, "get")) |said| return tree.failText(req.tag, E.IO, said);
+ var failed: anyerror = error.Unexpected;
+ const errno = get(p, pane, &failed);
+ // Naming the path, in words 9ns reads as the errno; a peer
+ // out of reach as a look or a Save says it.
+ if (errno != 0) {
+ const path = if (pane_files.fileOf(pane)) |f| f.path else "";
+ var why_buf: [48]u8 = undefined;
+ const why = if (pardes.Messages.dialReason(failed)) |r|
+ std.fmt.bufPrint(&why_buf, "dial failed: {s}", .{r}) catch unreachable // dialReason's words are short
+ else if (errno == E.NOENT) "no such file" else "cannot be read";
+ return tree.failText(req.tag, errno, std.fmt.bufPrint(&p.fs.ename, "get: {s}: {s}", .{ path[0..@min(path.len, 256)], why }) catch unreachable); // 256 and 48 fit 320
+ }
+ },
+ .lock => {
+ if (mine == null) return tree.failText(req.tag, E.INVAL, tree.e_bad_ctl);
+ if (other) return tree.failText(req.tag, E.BUSY, e_locked);
+ held = true;
+ if (apply) pane.fs.lock = mine;
+ },
+ .unlock => {
+ if (!held) return tree.failText(req.tag, E.INVAL, e_not_locked);
+ held = false;
+ if (apply) pane.fs.lock = null;
+ },
+ .answer => {
+ // With a question up, what it offers.
+ var offered: [64]u8 = undefined;
+ if (keys.questionChoices(p, p.paneBySerial(serial).?, &offered)) |choices|
+ return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "answer takes {s} or -", .{choices}) catch unreachable); // 64 fit 320
+ return tree.failText(req.tag, E.INVAL, "answer takes a choice or -");
+ },
} else if (std.mem.startsWith(u8, line, "answer ") and p.panes[p.paneBySerial(serial).?].?.prompt == .save) {
// Save's path, asked over 9P (`ask <serial> save path`).
if (!apply) continue;
@@ -1131,7 +1137,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
const asked = p.panes[id].?;
const path = std.mem.trim(u8, line["answer ".len..], " ");
var rec: [300]u8 = undefined;
- pardes.ctlfs.events.notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} {s}", .{ serial, path[0..@min(path.len, 256)] }) catch "");
+ pardes.ctlfs.events.notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} {s}", .{ serial, path[0..@min(path.len, 256)] }) catch unreachable); // a u32 and 256 fit 300
if (!std.mem.eql(u8, path, "-")) exec_line.saveTo(p, id, path);
asked.closePrompt();
} else if (std.mem.startsWith(u8, line, "answer ")) {
@@ -1145,7 +1151,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
if (!std.mem.eql(u8, choice, "-") and (choice.len != 1 or std.mem.indexOfScalar(u8, choices, choice[0]) == null)) {
var why: [96]u8 = undefined;
// The choice refused is what is quoted: `answer takes a b or - "z"`.
- return refuseQuoting(p, req, std.fmt.bufPrint(&why, "answer takes {s} or -", .{choices}) catch "answer takes a choice or -", choice, "");
+ return refuseQuoting(p, req, std.fmt.bufPrint(&why, "answer takes {s} or -", .{choices}) catch unreachable, choice, ""); // 64 fit 96
}
if (apply) _ = keys.answerQuestion(p, id, if (choice[0] == '-') null else choice[0]);
} else if (!apply) {
@@ -1175,65 +1181,54 @@ fn acmeCtl(p: *Pardes, req: Req, serial: u32, line: []const u8, apply: bool) Acm
const File = tree.PaneFile;
// A word written to one of the pane's own files, as acme's is to its.
const Into = struct { file: File, data: []const u8 };
- // `name` takes all after its one blank, as the name file takes what is
- // written. A second blank after the word is refused, not taken as the
- // name's first byte: a line's words are split at blanks.
- if (std.mem.eql(u8, word, "name") and rest.len > 0 and line[word.len + 1] == ' ')
- return .{ .refused = tree.failText(req.tag, E.INVAL, "bad character in file name: a blank at its start") };
- // `name` with nothing after it names nothing: said so, not an unknown word.
- if (std.mem.eql(u8, word, "name") and rest.len == 0)
- return .{ .refused = tree.failText(req.tag, E.INVAL, "invalid file name: name takes the name, and there is none") };
- const into: ?Into = if (std.mem.eql(u8, word, "name") and rest.len > 0)
- .{ .file = .name, .data = line[word.len + 1 ..] }
- else if (std.mem.eql(u8, line, "clean"))
- .{ .file = .dirty, .data = "0" }
- else if (std.mem.eql(u8, line, "dirty"))
- .{ .file = .dirty, .data = "1" }
- else if (std.mem.eql(u8, line, "mark"))
- .{ .file = .mark, .data = "1" }
- else if (std.mem.eql(u8, line, "nomark"))
- .{ .file = .mark, .data = "0" }
- else
- null;
- if (into) |w| {
- if (!apply) return .done;
- const r = pane_files.write(p, .{ .tag = req.tag, .op = .write, .node = tree.Node.of(serial, w.file), .data = w.data }, id, pane, w.file);
- return if (r.status == .err) .{ .refused = r } else .done;
+ const Word = enum { name, clean, dirty, mark, nomark, put, del, delete, @"dot=addr", @"addr=dot", @"limit=addr", show, cleartag, dump, dumpdir, font, menu, nomenu };
+ const w = std.meta.stringToEnum(Word, word) orelse return .no;
+ // name, dump, dumpdir and font take what follows them; the rest are a line alone.
+ switch (w) {
+ .name, .dump, .dumpdir, .font => {},
+ else => if (word.len != line.len) return .no,
}
- if (std.mem.eql(u8, line, "put")) return .{ .builtin = "Save" };
- if (std.mem.eql(u8, line, "del")) return .{ .builtin = "Del" };
- if (std.mem.eql(u8, line, "delete")) return .{ .builtin = "Delete" };
const pf = &pane.fs;
- if (std.mem.eql(u8, line, "dot=addr")) {
- if (apply) pane_files.setDot(pane, pf.addr);
- return .done;
- }
- if (std.mem.eql(u8, line, "addr=dot")) {
- if (apply) pf.addr = pane_files.dotOf(pane);
- return .done;
- }
- if (std.mem.eql(u8, line, "limit=addr")) {
- if (apply) pf.limit = pf.addr;
- return .done;
- }
- if (std.mem.eql(u8, line, "show")) {
- if (apply) pane_files.showOffset(pane, pane_files.dotOf(pane).q0);
- return .done;
- }
- if (std.mem.eql(u8, line, "cleartag")) {
- if (apply) _ = pane_files.truncate(p, pane, .tag);
- return .done;
- }
- const none: ?[]const u8 = if (std.mem.eql(u8, word, "dump") or std.mem.eql(u8, word, "dumpdir"))
- "a pane is dumped with the session: Dump and DumpDir on /ctl"
- else if (std.mem.eql(u8, word, "font"))
- "the font is the session's: Font on /ctl"
- else if (std.mem.eql(u8, line, "menu") or std.mem.eql(u8, line, "nomenu"))
- "pardes has no menu"
- else
- null;
- if (none) |why| return .{ .refused = tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s}: {s}", .{ word, why }) catch "invalid: acme's ctl word") };
- return .no;
+ const into: Into = switch (w) {
+ // `name` takes all after its one blank, as the name file takes what
+ // is written; with nothing after it, it names nothing (said so, not
+ // an unknown word), and a second blank is refused, not taken as the
+ // name's first byte: a line's words are split at blanks.
+ .name => if (rest.len == 0)
+ return .{ .refused = tree.failText(req.tag, E.INVAL, "invalid file name: name takes the name, and there is none") }
+ else if (line[word.len + 1] == ' ')
+ return .{ .refused = tree.failText(req.tag, E.INVAL, "bad character in file name: a blank at its start") }
+ else
+ .{ .file = .name, .data = line[word.len + 1 ..] },
+ .clean => .{ .file = .dirty, .data = "0" },
+ .dirty => .{ .file = .dirty, .data = "1" },
+ .mark => .{ .file = .mark, .data = "1" },
+ .nomark => .{ .file = .mark, .data = "0" },
+ .put => return .{ .builtin = "Save" },
+ .del => return .{ .builtin = "Del" },
+ .delete => return .{ .builtin = "Delete" },
+ .@"dot=addr", .@"addr=dot", .@"limit=addr", .show, .cleartag => {
+ if (apply) switch (w) {
+ .@"dot=addr" => pane_files.setDot(pane, pf.addr),
+ .@"addr=dot" => pf.addr = pane_files.dotOf(pane),
+ .@"limit=addr" => pf.limit = pf.addr,
+ .show => pane_files.showOffset(pane, pane_files.dotOf(pane).q0),
+ else => _ = pane_files.truncate(p, pane, .tag),
+ };
+ return .done;
+ },
+ .dump, .dumpdir, .font, .menu, .nomenu => {
+ const why = switch (w) {
+ .font => "the font is the session's: Font on /ctl",
+ .menu, .nomenu => "pardes has no menu",
+ else => "a pane is dumped with the session: Dump and DumpDir on /ctl",
+ };
+ return .{ .refused = tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s}: {s}", .{ word, why }) catch unreachable) }; // short literals
+ },
+ };
+ if (!apply) return .done;
+ const r = pane_files.write(p, .{ .tag = req.tag, .op = .write, .node = tree.Node.of(serial, into.file), .data = into.data }, id, pane, into.file);
+ return if (r.status == .err) .{ .refused = r } else .done;
}
const e_not_locked = "pane not locked by this open";
@@ -1264,9 +1259,9 @@ pub fn getRefused(p: *Pardes, pane: *Pane, word: []const u8) ?[]const u8 {
if (listed) |content| panes.Output.openUnsaved(p, id, content);
var notice: [64]u8 = undefined;
p.fs.unlogged = true;
- p.setMessage(id, std.fmt.bufPrint(&notice, "1 unsaved pane \u{2014} {s} again to discard", .{word}) catch "1 unsaved pane");
+ p.setMessage(id, std.fmt.bufPrint(&notice, "1 unsaved pane \u{2014} {s} again to discard", .{word}) catch unreachable); // word is get, Get or e
p.fs.unlogged = false;
- return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path, word }) catch "Modified (get again to discard)";
+ return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path[0..@min(f.path.len, 256)], word }) catch unreachable; // 256 fit 320
}
/// acme's `Get file`, and Edit's `e file`: the file at `path` (absolute)
@@ -1331,7 +1326,7 @@ pub fn get(p: *Pardes, pane: *Pane, failed: *anyerror) u16 {
f.disk_gone = false;
if (discarded) {
var rec: [32]u8 = undefined;
- pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} reloaded", .{pane.serial}) catch "");
+ pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} reloaded", .{pane.serial}) catch unreachable); // a u32 fits 32
}
return 0;
}
@@ -1423,7 +1418,7 @@ test "Zerox twins: a Save from one, performed, cleans both" {
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
const p = try withFile(testing.allocator, "one\n");
defer p.deinit();
- var name: [std.fs.max_path_bytes + 8]u8 = undefined;
+ var name: [std.Io.Dir.max_path_bytes + 8]u8 = undefined;
_ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&name, "{s}/z.txt\n", .{dir}));
try testing.expect(p.executeBuiltinLine(0, "Zerox"));
const twin_id = for (p.panes, 0..) |slot, id| {
@@ -1623,7 +1618,7 @@ test "a refusal's +Unsaved goes in the session's directory when the active pane'
const f = pane.file orelse continue;
if (f.output) |o| if (o.from == .unsaved) break f.path;
} else return error.NoUnsavedPane;
- try testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(unsaved).?);
+ try testing.expectEqualStrings(p.sessionDir(), std.Io.Dir.path.dirname(unsaved).?);
}
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 6fd0d345..a25b97b2 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -131,7 +131,7 @@ pub fn noteRetire(p: *Pardes, pane: *Pane) void {
// hears the end.
if (pane.prompt == .repl_choice or pane.prompt == .del_side or pane.prompt == .save) {
var rec: [32]u8 = undefined;
- notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} -", .{pane.serial}) catch "");
+ notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} -", .{pane.serial}) catch unreachable); // a u32 fits 32
}
noteLog(p, .del, pane);
}
@@ -174,7 +174,7 @@ pub fn noteLogAs(p: *Pardes, kind: LogKind, pane: *Pane, path: []const u8) void
var name_buf: [4 * 4096]u8 = undefined;
// As /index shows it: a newline in the name is `\n`.
const name = shown(path, &name_buf);
- pushLog(p, std.fmt.bufPrint(&buf, "{s} {d} {s}\n", .{ @tagName(kind), pane.serial, name }) catch return);
+ pushLog(p, std.fmt.bufPrint(&buf, "{s} {d} {s}\n", .{ @tagName(kind), pane.serial, name }) catch unreachable); // name is at most name_buf's
}
/// Records `msg <serial> <text>` for what the editor said, `-` for no pane.
@@ -191,7 +191,7 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void {
pushCounting(p, (if (serial == 0)
std.fmt.bufPrint(&buf, "msg - {s}{s}\n", .{ kept, cut })
else
- std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept, cut })) catch return, said);
+ std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept, cut })) catch unreachable, said); // kept is at most cap
}
/// `notePath` for an `err` record: the same one again straight after is
@@ -199,7 +199,7 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void {
pub fn noteErrCounted(p: *Pardes, text: []const u8) void {
bootFirst(p);
var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined;
- pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text}) catch return, text);
+ pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text[0..@min(text.len, buf.len - 16)]}) catch unreachable, text);
}
/// Records `<what> <path>`: `dump <path>` when a Dump is written,
@@ -207,7 +207,8 @@ pub fn noteErrCounted(p: *Pardes, text: []const u8) void {
pub fn notePath(p: *Pardes, what: []const u8, path: []const u8) void {
bootFirst(p);
var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined;
- pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what, path }) catch return);
+ // unreachable: a record's word is a short literal, and the path is cut to fit.
+ pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what, path[0..@min(path.len, buf.len - 16)] }) catch unreachable);
}
/// Records `err <serial|-> <file>: <why>` for a write that was refused or
@@ -228,17 +229,17 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void {
// The root's exec or look ran at the keyboard's pane: its
// failure is that pane's, as a click there would be.
if ((f == .exec or f == .look) and p.fs.ran_at != 0)
- serial = std.fmt.bufPrint(&name, "{d}", .{p.fs.ran_at}) catch "-";
+ serial = std.fmt.bufPrint(&name, "{d}", .{p.fs.ran_at}) catch unreachable; // a u32 fits 32
},
.col => |c| {
serial = "-";
file = (if (c.file == .dir)
std.fmt.bufPrint(&name, "col/{d}", .{c.serial})
else
- std.fmt.bufPrint(&name, "col/{d}/{s}", .{ c.serial, @tagName(c.file) })) catch "col";
+ std.fmt.bufPrint(&name, "col/{d}/{s}", .{ c.serial, @tagName(c.file) })) catch unreachable; // a u32 and a file's name fit 32
},
.pane => |pt| {
- serial = std.fmt.bufPrint(&name, "{d}", .{pt.serial}) catch "-";
+ serial = std.fmt.bufPrint(&name, "{d}", .{pt.serial}) catch unreachable; // a u32 fits 32
file = switch (pt.file) {
.pty_ctl => "pty/ctl",
.pty_status => "pty/status",
@@ -255,7 +256,7 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void {
const reason = if (why.len > file.len + 2 and std.ascii.startsWithIgnoreCase(why, file) and std.mem.startsWith(u8, why[file.len..], ": ")) why[file.len + 2 ..] else why;
// A long reason is cut between words, with an ellipsis, never mid-word.
const kept = pardes.Messages.clip(reason, 200);
- const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}{s}\n", .{ serial, file, kept, if (kept.len < reason.len) "…" else "" }) catch return;
+ const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}{s}\n", .{ serial, file, kept, if (kept.len < reason.len) "…" else "" }) catch unreachable; // 10 + 32 + 200 + 11 fit 256
for (record[0 .. record.len - 1]) |*c| if (c.* < ' ') {
c.* = ' ';
};
@@ -298,7 +299,8 @@ fn pushCounting(p: *Pardes, raw: []u8, full: []const u8) void {
};
if (!std.mem.eql(u8, said, record[0 .. record.len - 1]) or p.fs.log_full_hash != full_hash) return pushLog(p, record);
var counted: [pardes.Messages.LoggedMessage.cap + 64]u8 = undefined;
- const again = std.fmt.bufPrint(&counted, "{s} (x{d})\n", .{ said, times +| 1 }) catch return;
+ // A repeat too long to count is pushed as a line of its own.
+ const again = std.fmt.bufPrint(&counted, "{s} (x{d})\n", .{ said, times +| 1 }) catch return pushLog(p, record);
if (!followerRead(p, last.seq)) p.fs.log.buf.shrinkRetainingCapacity(last.at);
pushLog(p, again);
}
@@ -441,7 +443,7 @@ pub const LogOpen = struct {
/// An open freezes the ring's text, so `cat log` answers what happened lately
/// and ends; `next` is where a follower picks up after it.
-pub fn freezeLog(p: *Pardes) !LogOpen {
+pub fn freezeLog(p: *Pardes) error{OutOfMemory}!LogOpen {
var text: std.ArrayList(u8) = .empty;
errdefer text.deinit(p.gpa);
var at = p.fs.log.head;
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 704f1ac8..52ae9494 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -399,8 +399,8 @@ pub fn read(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply
return switch (file) {
.name => name: {
const out = p.fs.stage(p.gpa);
- out.appendSlice(p.gpa, nameOf(p, pane)) catch {};
- out.append(p.gpa, '\n') catch {};
+ out.appendSlice(p.gpa, nameOf(p, pane)) catch break :name Reply.fail(req.tag, E.NOMEM);
+ out.append(p.gpa, '\n') catch break :name Reply.fail(req.tag, E.NOMEM);
break :name tree.stagedReply(p, req);
},
.body => readBody(p, req, id, pane),
@@ -440,13 +440,13 @@ pub fn read(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply
/// happens to bound nothing.
fn readRange(p: *Pardes, req: Req, r: ?State.Range) Reply {
const out = p.fs.stage(p.gpa);
- if (r) |range| out.print(p.gpa, "{d:>11} {d:>11} ", .{ range.q0, range.q1 }) catch {};
+ if (r) |range| out.print(p.gpa, "{d:>11} {d:>11} ", .{ range.q0, range.q1 }) catch return Reply.fail(req.tag, E.NOMEM);
return tree.stagedReply(p, req);
}
fn readFlag(p: *Pardes, req: Req, on: bool) Reply {
const out = p.fs.stage(p.gpa);
- out.appendSlice(p.gpa, if (on) "1\n" else "0\n") catch {};
+ out.appendSlice(p.gpa, if (on) "1\n" else "0\n") catch return Reply.fail(req.tag, E.NOMEM);
return tree.stagedReply(p, req);
}
@@ -886,14 +886,14 @@ fn writeName(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
// Words 9ns maps to EINVAL, as every refusal of a name here.
if (fileOf(pane) == null) return tree.failText(req.tag, E.INVAL, unnamed(pane));
var home_buf: [4096]u8 = undefined;
- const full = std.fs.path.resolvePosix(p.scratch.allocator(), &.{ pardes.Pardes.paneDir(pane), fs.expandHome(name, &home_buf) }) catch
+ const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ pardes.Pardes.paneDir(pane), fs.expandHome(name, &home_buf) }) catch
return Reply.fail(req.tag, E.NOMEM);
- if (!std.fs.path.isAbsolute(full) or full.len >= 4096) return tree.failText(req.tag, E.INVAL, "invalid file name: longer than a path may be");
+ if (!std.Io.Dir.path.isAbsolute(full) or full.len >= 4096) return tree.failText(req.tag, E.INVAL, "invalid file name: longer than a path may be");
// A directory (`~`, `/`, `foo/`) is no file to name a pane after: a
// Save could only fail. Said now, EISDIR.
const is_dir = name[name.len - 1] == '/' or std.mem.eql(u8, full, "/") or
(if (fs.localPath(full)) |local| exec.kindOf(local) == .directory else false);
- if (is_dir) return tree.failText(req.tag, E.ISDIR, std.fmt.bufPrint(&p.fs.ename, "name: {s} is a directory, not a file", .{full[0..@min(full.len, 256)]}) catch "name: is a directory, not a file");
+ if (is_dir) return tree.failText(req.tag, E.ISDIR, std.fmt.bufPrint(&p.fs.ename, "name: {s} is a directory, not a file", .{full[0..@min(full.len, 256)]}) catch unreachable); // 256 fit 320
nameBuffer(p, id, full, false) catch |err| return Reply.fail(req.tag, switch (err) {
error.OutOfMemory => E.NOMEM,
else => E.INVAL,
@@ -906,7 +906,7 @@ fn writeName(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) !void {
const pane = p.panes[id] orelse return error.NoPane;
const f = fileOf(pane) orelse return error.NotFile;
- if (!std.fs.path.isAbsolute(full) or full.len == 0 or full.len >= 4096)
+ if (!std.Io.Dir.path.isAbsolute(full) or full.len == 0 or full.len >= 4096)
return error.InvalidName;
if (std.mem.indexOfAny(u8, full, "\x00\n") != null) return error.InvalidName;
if (std.mem.eql(u8, f.path, full)) return;
@@ -949,7 +949,7 @@ pub fn appendErrors(p: *Pardes, id: usize, text: []const u8) ?usize {
const qf = fileOf(q) orelse continue;
const o = qf.output orelse continue;
if (std.meta.activeTag(o.from) != .errors) continue;
- if (!std.mem.eql(u8, std.fs.path.dirname(qf.path) orelse "", dir)) continue;
+ if (!std.mem.eql(u8, std.Io.Dir.path.dirname(qf.path) orelse "", dir)) continue;
return spliceBody(p, q, qf.content.len, qf.content.len, text);
}
const free = p.freeSlot() orelse return null;
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig
index 65e8589f..2a4fc1ed 100644
--- a/src/ninep/pty.zig
+++ b/src/ninep/pty.zig
@@ -12,11 +12,12 @@ const E = tree.E;
const PaneFile = tree.PaneFile;
pub fn fileNamed(name: []const u8) ?PaneFile {
- if (std.mem.eql(u8, name, "ctl")) return .pty_ctl;
- if (std.mem.eql(u8, name, "status")) return .pty_status;
- if (std.mem.eql(u8, name, "data")) return .pty_data;
- if (std.mem.eql(u8, name, "run")) return .pty_run;
- return null;
+ return switch (std.meta.stringToEnum(enum { ctl, status, data, run }, name) orelse return null) {
+ .ctl => .pty_ctl,
+ .status => .pty_status,
+ .data => .pty_data,
+ .run => .pty_run,
+ };
}
const Verb = enum { winsize, sig, exec };
@@ -37,12 +38,13 @@ const e_winsize_range = std.fmt.comptimePrint("invalid winsize: out of range, 1x
const e_winsize_rows = std.fmt.comptimePrint("invalid winsize: at least {d} rows", .{pty_rows_min});
fn signalNamed(word: []const u8) ?pardes.PtySignal {
- if (std.mem.eql(u8, word, "INT")) return .int;
- if (std.mem.eql(u8, word, "TERM")) return .term;
- if (std.mem.eql(u8, word, "HUP")) return .hup;
- if (std.mem.eql(u8, word, "QUIT")) return .quit;
- if (std.mem.eql(u8, word, "KILL")) return .kill;
- return null;
+ return switch (std.meta.stringToEnum(enum { INT, TERM, HUP, QUIT, KILL }, word) orelse return null) {
+ .INT => .int,
+ .TERM => .term,
+ .HUP => .hup,
+ .QUIT => .quit,
+ .KILL => .kill,
+ };
}
pub fn writeCtl(p: *Pardes, req: Req, id: usize) Reply {
@@ -59,13 +61,13 @@ pub fn writeCtl(p: *Pardes, req: Req, id: usize) Reply {
// refused before anything runs, as Term there is.
const dir = pane.cwdSlice();
if (pardes.exec.missingDir(p, dir))
- return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch "exec: no such directory");
+ return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320
// Nor is a shell that is not there, or a script whose
// interpreter is not: refused, and the running shell kept.
const bin = pane.shell orelse p.shellBin();
var why: [320]u8 = undefined;
if (pardes.tape.value(.shell, @import("../host_io.zig").Shell.refusal, .{ bin[0..@min(bin.len, 200)], &why })) |refused|
- return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}", .{refused}) catch "exec: no such shell");
+ return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}", .{refused[0..@min(refused.len, 300)]}) catch unreachable); // 300 fit 320
};
if (verb(p, id, line, apply)) |why| return tree.failText(req.tag, E.INVAL, why);
}
@@ -140,7 +142,7 @@ pub fn readStatus(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
(if (marks) |m| m.prompts > 0 and (m.phase != .input or !pardes.panes.terminal.promptInputEmpty(pane)) else false)));
const out = p.fs.stage(p.gpa);
const size = winsize(pane);
- out.print(p.gpa, "{d:>11} {d:>11} {d:>11}\n", .{ size[0], size[1], @intFromBool(busy) }) catch {};
+ out.print(p.gpa, "{d:>11} {d:>11} {d:>11}\n", .{ size[0], size[1], @intFromBool(busy) }) catch return Reply.fail(req.tag, E.NOMEM);
return tree.stagedReply(p, req);
}
diff --git a/src/ninep/screen.zig b/src/ninep/screen.zig
index 33a8717b..634ef640 100644
--- a/src/ninep/screen.zig
+++ b/src/ninep/screen.zig
@@ -70,12 +70,12 @@ pub fn readSnapshot(p: *Pardes, req: Req, pane: ?*Pane) Reply {
}
/// /listeners' text, a dial a line, in the step's scratch.
-pub fn listenersText(p: *Pardes) []const u8 {
+pub fn listenersText(p: *Pardes) std.Io.Writer.Error![]const u8 {
var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
- if (p.fs.socket_path.len != 0) text.writer.print("unix!{s}\n", .{p.fs.socket_path}) catch {};
+ if (p.fs.socket_path.len != 0) try text.writer.print("unix!{s}\n", .{p.fs.socket_path});
if (p.fs.tcp_address) |address| switch (address) {
- .ip4 => |ip| text.writer.print("tcp!{d}.{d}.{d}.{d}!{d}\n", .{ ip.bytes[0], ip.bytes[1], ip.bytes[2], ip.bytes[3], ip.port }) catch {},
- .ip6 => |ip| text.writer.print("tcp!{f}!{d}\n", .{ std.Io.net.Ip6Address.Unresolved{ .bytes = ip.bytes, .interface_name = null }, ip.port }) catch {},
+ .ip4 => |ip| try text.writer.print("tcp!{d}.{d}.{d}.{d}!{d}\n", .{ ip.bytes[0], ip.bytes[1], ip.bytes[2], ip.bytes[3], ip.port }),
+ .ip6 => |ip| try text.writer.print("tcp!{f}!{d}\n", .{ std.Io.net.Ip6Address.Unresolved{ .bytes = ip.bytes, .interface_name = null }, ip.port }),
};
return text.written();
}
diff --git a/src/ninep/sources.zig b/src/ninep/sources.zig
index 846ab758..32edb1f6 100644
--- a/src/ninep/sources.zig
+++ b/src/ninep/sources.zig
@@ -69,7 +69,7 @@ pub fn handle(p: *Pardes, req: Req) Reply {
const found = info(req.node) orelse return Reply.fail(req.tag, E.NOENT);
const attr: Reply.Attr = .{
.node = req.node,
- .name = std.fs.path.basename(found.path),
+ .name = std.Io.Dir.path.basename(found.path),
.dir = found.dir,
.size = if (found.dir) 0 else found.contents.len,
.mode = if (found.dir) 0o555 else 0o444,
@@ -82,7 +82,7 @@ pub fn handle(p: *Pardes, req: Req) Reply {
.lookup => {
if (!found.dir) return Reply.fail(req.tag, E.NOTDIR);
if (std.mem.eql(u8, req.data, "..")) {
- const parent = std.fs.path.dirname(found.path) orelse "";
+ const parent = std.Io.Dir.path.dirname(found.path) orelse "";
if (parent.len == 0) return tree.handle(p, .{ .tag = req.tag, .op = .getattr, .node = tree.root });
const parent_node = node(parent) orelse return Reply.fail(req.tag, E.NOENT);
return handle(p, .{ .tag = req.tag, .op = .getattr, .node = parent_node });
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.