diff options
Diffstat (limited to 'core/ninep')
| -rw-r--r-- | core/ninep/ctl.zig | 42 | ||||
| -rw-r--r-- | core/ninep/events.zig | 22 | ||||
| -rw-r--r-- | core/ninep/pane.zig | 4 | ||||
| -rw-r--r-- | core/ninep/pty.zig | 8 |
4 files changed, 38 insertions, 38 deletions
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index a4f16597..cf68fa76 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -228,7 +228,7 @@ pub fn command(p: *Pardes, req: Req, serial: ?u32, exec: bool, in_tag: bool) Rep } if (p.panes[id] == null) return Reply.fail(req.tag, E.NOENT); defer if (scratch) |s| if (v.active != s) if (p.panes[s]) |sp| if (sp.file) |f| { - if (f.content.len == 0) p.removePane(s, null) catch |err| p.reportError(s, "exec", err); + if (f.content.len == 0) p.removePane(s, null) catch |err| p.reportError(.at(s), "exec", err); }; p.fs.ran_at = p.panes[id].?.serial; p.fs.no_pane_slot = false; @@ -724,7 +724,7 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM /// The editor's step: the text of /pager opens closed unread goes in. pub fn fillClosedPagers(p: *Pardes) void { for (p.fs.pages.items) |*page| { - fillPager(p, page.serial, &page.bytes) catch |err| if (p.paneBySerial(page.serial)) |id| p.reportError(id, "pager", err); + fillPager(p, page.serial, &page.bytes) catch |err| if (p.paneBySerial(page.serial)) |id| p.reportError(.at(id), "pager", err); page.bytes.deinit(p.gpa); } p.fs.pages.clearRetainingCapacity(); @@ -1252,7 +1252,7 @@ pub fn getRefused(p: *Pardes, pane: *Pane, word: []const u8) ?[]const u8 { if (listed) |content| panes.Output.openUnsaved(p, id, content); var notice: pardes.Kind.Buf(64) = .{}; p.fs.unlogged = true; - p.setMessage(id, notice.print("1 unsaved pane \u{2014} {s} again to discard", .{word})); + p.setMessage(.at(id), notice.print("1 unsaved pane \u{2014} {s} again to discard", .{word})); p.fs.unlogged = false; return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path[0..@min(f.path.len, 256)], word[0..@min(word.len, 16)] }) catch &p.fs.ename; // cut to ename's 320 } @@ -1638,7 +1638,7 @@ test "a builtin's Verbose announcement is logged only when it succeeds, its fail var save_buf: [64]u8 = undefined; const said_save = try std.fmt.bufPrint(&save_buf, "msg {d} Save\n", .{serial}); _ = wr(p, Node.of(serial, .exec), "Save\n"); - p.saveFailed(@intCast(p.paneBySerial(serial).?), "/test.txt", error.AccessDenied); + p.saveFailed(.at(p.paneBySerial(serial).?), "/test.txt", error.AccessDenied); try testing.expect(!th.logHas(p, said_save)); // One that does what it says keeps its announcement. _ = wr(p, Node.of(serial, .exec), "Undo\n"); @@ -1902,7 +1902,7 @@ test "Term in a directory that is not there fails and makes no pane; a shell tha _ = wr(p, Node.of(serial, .name), "/tmp/f.txt\n"); try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Term\n").reply.status); const term = p.view().active; - p.shellFailed(@intCast(term), error.FileNotFound); + p.shellFailed(.at(term), error.FileNotFound); const run_node = Node.of(p.panes[term].?.serial, .pty_run); const h = call(p, .{ .tag = 1, .op = .open, .node = run_node, .omode = 2 }).reply.handle; _ = call(p, .{ .tag = 2, .op = .write, .node = run_node, .handle = h, .data = "true\n" }); @@ -1982,17 +1982,17 @@ test "a terminal told the directory it already goes by logs no rename" { p.update(.tick); // announced const term = p.view().active; // The host says where its shell started: where it was already named. - p.setCwd(term, "/tmp"); + p.setCwd(.at(term), "/tmp"); var rec: [32]u8 = undefined; try testing.expect(!th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} ", .{p.panes[term].?.serial}))); // This process's directory, asked before the shell has said anything // (so before its chdir): not taken. const session = p.sessionDir(); - p.setCwd(term, session); + p.setCwd(.at(term), session); try testing.expect(!th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} ", .{p.panes[term].?.serial}))); p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "$ " } }); // Somewhere else is a rename. - p.setCwd(term, "/usr"); + p.setCwd(.at(term), "/usr"); try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} /usr", .{p.panes[term].?.serial}))); } @@ -2000,7 +2000,7 @@ test "a terminal with text typed at its prompt is never typed into: a look at it const p = try th.withTerm(testing.allocator); defer p.deinit(); const term = p.paneBySerial(serialOf(p)).?; - p.setCwd(term, "/tmp"); + p.setCwd(.at(term), "/tmp"); p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } }); while (p.nextEffect()) |_| {} var count: usize = 0; @@ -2042,7 +2042,7 @@ test "a command line from a missing directory fails ENOENT and makes no pane; a _ = wr(p, Node.of(serial, .name), "/tmp/f.txt\n"); try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "echo hi\n").reply.status); const cmd = p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, Node.of(serial, .exec), 0, 64).bytes, "\n"), 10)).?; - p.shellFailed(@intCast(cmd), error.FileNotFound); + p.shellFailed(.at(cmd), error.FileNotFound); const pane = p.panes[cmd].?; try testing.expect(pane.command_done); try testing.expectEqual(@as(?u8, 127), pane.command_status); @@ -2057,13 +2057,13 @@ test "pty/ctl exec in a directory that is gone fails ENOENT; a shell that cannot p.host = .{ .vtable = &th.starting }; defer p.host = .{}; const serial = serialOf(p); - p.setCwd(p.paneBySerial(serial).?, "/tmp/pardes-no-such-dir-zz"); + p.setCwd(.at(p.paneBySerial(serial).?), "/tmp/pardes-no-such-dir-zz"); const refused = wr(p, Node.of(serial, .pty_ctl), "exec\n"); try testing.expectEqual(E.NOENT, refused.errno()); try testing.expectStringStartsWith(refused.reply.ename, "exec: /tmp/pardes-no-such-dir-zz: no such directory"); // The host's own failure is the waiting write's (late_failure). p.fs.late_failure_len = 0; - p.shellFailed(@intCast(p.paneBySerial(serial).?), error.AccessDenied); + p.shellFailed(.at(p.paneBySerial(serial).?), error.AccessDenied); try testing.expectEqualStrings("shell: permission denied", p.fs.late_failure[0..p.fs.late_failure_len]); } @@ -2095,14 +2095,14 @@ test "a script whose interpreter is not there: Term refuses it up front, only an // one goes. const id = p.paneBySerial(serial).?; p.panes[id].?.shell = try p.gpa.dupe(u8, try std.fmt.bufPrint(&line, "{s}/bad", .{dir})); - p.setCwd(id, dir); + p.setCwd(.at(id), dir); const exec_refused = wr(p, Node.of(serial, .pty_ctl), "exec\n"); try testing.expectEqual(E.NOENT, exec_refused.errno()); try testing.expectEqualStrings("exec: interpreter /no/such/interp not found", exec_refused.reply.ename); // One the host found could not start (the script changed after): said // with the interpreter's name, and the running shell is not gone. p.fs.late_failure_len = 0; - p.restartFailed(@intCast(id), error.InterpreterNotFound); + p.restartFailed(.at(id), error.InterpreterNotFound); try testing.expectEqualStrings("shell: interpreter /no/such/interp not found", p.fs.late_failure[0..p.fs.late_failure_len]); try testing.expect(!p.panes[id].?.shell_failed); } @@ -2163,7 +2163,7 @@ test "a buffer whose file was deleted on disk is dirty, and Del asks first" { defer p.deinit(); const serial = serialOf(p); try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); - pardes.panes.File.deleted(p, @intCast(p.paneBySerial(serial).?)); + pardes.panes.File.deleted(p, .at(p.paneBySerial(serial).?)); try testing.expectEqualStrings("1", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); try testing.expectEqual(Status.err, wr(p, Node.of(serial, .ctl), "Del\n").reply.status); try testing.expect(p.paneBySerial(serial) != null); @@ -2176,7 +2176,7 @@ test "a failure said while a 9P write waits on it posts no msg, only the write's const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); p.fs.write_waits = true; - p.saveFailed(@intCast(p.view().active), "/nowhere/zz.txt", error.FileNotFound); + p.saveFailed(.at(p.view().active), "/nowhere/zz.txt", error.FileNotFound); p.fs.write_waits = false; try testing.expect(!th.logHas(p, "msg ")); try testing.expect(p.fs.late_failure_len > 0); @@ -2304,7 +2304,7 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt const p = try th.withTerm(testing.allocator); defer p.deinit(); const term = p.paneBySerial(serialOf(p)).?; - p.setCwd(term, "/tmp/two\nlines\x07\x7f\xc2\x85\xff"); + p.setCwd(.at(term), "/tmp/two\nlines\x07\x7f\xc2\x85\xff"); const index = rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes; // Each byte as itself, so the name decodes to what it is. try testing.expect(std.mem.indexOf(u8, index, "/tmp/two\\nlines\\x07\\x7f\\xc2\\x85\\xff ") != null); @@ -2561,8 +2561,8 @@ test "get names the path it could not read, logs the edits it threw away, and a var want: [512]u8 = undefined; try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "get: {s}: no such file", .{path}), missing.reply.ename); // Deleted on disk: said once. - pardes.panes.File.deleted(p, 0); - pardes.panes.File.deleted(p, 0); + pardes.panes.File.deleted(p, .at(0)); + pardes.panes.File.deleted(p, .at(0)); var rec: [32]u8 = undefined; const log = @backingInt(tree.TopFile.log); const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; @@ -2712,10 +2712,10 @@ test "a Save whose directory is missing because one above refuses says permissio defer p.deinit(); // The refusing directory is Linux's /proc/1/root. if (comptime @import("builtin").os.tag == .linux) { - p.saveFailed(0, "/proc/1/root/x/f.txt", error.FileNotFound); + p.saveFailed(.at(0), "/proc/1/root/x/f.txt", error.FileNotFound); try testing.expect(th.logHas(p, "Save /proc/1/root/x/f.txt: permission denied")); } - p.saveFailed(0, "/tmp/pardes-surely-missing-dir/f.txt", error.FileNotFound); + p.saveFailed(.at(0), "/tmp/pardes-surely-missing-dir/f.txt", error.FileNotFound); try testing.expect(th.logHas(p, "no such directory")); } diff --git a/core/ninep/events.zig b/core/ninep/events.zig index 1e740345..93a1187a 100644 --- a/core/ninep/events.zig +++ b/core/ninep/events.zig @@ -1180,7 +1180,7 @@ test "the log records whether or not anyone reads, and an open that follows wait ); // What the editor says is in the same stream, one line even when the // message had several. - p.setMessage(id, "save: two\nlines"); + p.setMessage(.at(id), "save: two\nlines"); try testing.expectEqualStrings( try std.fmt.bufPrint(&expected, "msg {d} save: two lines\n", .{serial}), rdf.next(p, log, fh, frozen).bytes, @@ -1198,7 +1198,7 @@ test "the log records whether or not anyone reads, and an open that follows wait // pieces rather than failing. A repeat the follower waits on, having // read the first, is its own line. const said_by = p.panes[0].?.serial; - p.setMessage(0, "same failure"); + p.setMessage(.at(0), "same failure"); var pieced: [64]u8 = undefined; var got: usize = 0; while (got == 0 or pieced[got - 1] != '\n') { @@ -1207,14 +1207,14 @@ test "the log records whether or not anyone reads, and an open that follows wait got += piece.len; } try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "msg {d} same failure\n", .{said_by}), pieced[0..got]); - p.setMessage(0, "same failure"); + p.setMessage(.at(0), "same failure"); try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "msg {d} same failure (x2)\n", .{said_by}), rdf.next(p, log, fh, frozen).bytes); // A follower the ring outran hears how much it missed, then carries on. var filler: [200]u8 = @splat('x'); for (0..p.fs.log.cap / filler.len + 8) |i| { _ = std.fmt.bufPrint(&filler, "{d:0>6}", .{i}) catch unreachable; // a repeat would collapse - p.setMessage(0, &filler); + p.setMessage(.at(0), &filler); } const lost = rdf.next(p, log, fh, frozen).bytes; try testing.expect(std.mem.startsWith(u8, lost, "lost ")); @@ -1226,7 +1226,7 @@ test "the log records whether or not anyone reads, and an open that follows wait // everything else pushed out ahead of it. p.fs.log.cap = 128; var huge: [300]u8 = @splat('y'); - p.setMessage(0, &huge); + p.setMessage(.at(0), &huge); const cut = call(p, .{ .tag = 11, .op = .open, .node = log }); const kept = call(p, .{ .tag = 12, .op = .read, .node = log, .handle = cut.reply.handle, .size = 512 }).bytes; try testing.expectEqual(@as(usize, 124), kept.len); @@ -1328,7 +1328,7 @@ test "a pane named before it is announced has its new under that name, and no re const shell = try p.newShell(free, ""); try testing.expectEqualStrings(p.sessionDir(), pane_files.nameOf(p, shell)); announce(p); - p.setCwd(free, p.sessionDir()); + p.setCwd(.at(free), p.sessionDir()); const after = try freezeLog(p); defer p.gpa.free(after.bytes); try testing.expect(std.mem.indexOf(u8, after.bytes, try std.fmt.bufPrint(&want, "rename {d} ", .{shell.serial})) == null); @@ -1427,12 +1427,12 @@ test "follow new skips what the log held and waits for what comes after" { defer p.deinit(); p.update(.tick); // the pane's `new` is logged first while (p.nextEffect()) |_| {} - p.setMessage(0, "before the open"); + p.setMessage(.at(0), "before the open"); const log = @backingInt(tree.TopFile.log); const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = log, .handle = h, .data = "follow new\n" }).reply.status); try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = log, .handle = h, .size = 4096 }).reply.status); - p.setMessage(0, "after it"); + p.setMessage(.at(0), "after it"); try testing.expect(std.mem.endsWith(u8, call(p, .{ .tag = 4, .op = .read, .node = log, .handle = h, .size = 4096 }).bytes, " after it\n")); _ = call(p, .{ .tag = 5, .op = .release, .node = log, .handle = h }); } @@ -1482,10 +1482,10 @@ test "two failures that agree only in what their records cut are two records, no const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); const long = std.mem.asBytes(&@as([80][4]u8, @splat("why ".*))); - p.setMessage(0, long ++ "first"); - p.setMessage(0, long ++ "second"); + p.setMessage(.at(0), long ++ "first"); + p.setMessage(.at(0), long ++ "second"); try testing.expect(!th.logHas(p, "(x2)")); - p.setMessage(0, long ++ "second"); + p.setMessage(.at(0), long ++ "second"); try testing.expect(th.logHas(p, "(x2)")); } diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig index 96a50703..76765535 100644 --- a/core/ninep/pane.zig +++ b/core/ninep/pane.zig @@ -693,7 +693,7 @@ pub fn applyTagTruncation(p: *Pardes, pane: *Pane) void { pf.tag_trunc_pending = false; // An edit like a keyboard one: `u` in the tag brings it back. pane.tag.remember(p.gpa, if (pane.tag.own) |own| .{ .text = own } else null) catch |err| - return p.reportError(p.paneBySerial(pane.serial) orelse return, "tag", err); + return p.reportError(.at(p.paneBySerial(pane.serial) orelse return), "tag", err); const empty = p.gpa.alloc(u8, 0) catch unreachable; // no byte: the allocator is not asked if (pane.tag.own) |own| p.gpa.free(own); pane.tag.own = empty; @@ -1198,7 +1198,7 @@ test "a long path's failed Save keeps its reason" { const id = p.paneBySerial(serial).?; try nameBuffer(p, id, long, false); p.fs.late_failure_len = 0; - p.saveFailed(@intCast(id), long, error.AccessDenied); + p.saveFailed(.at(id), long, error.AccessDenied); const late = p.fs.late_failure[0..p.fs.late_failure_len]; try testing.expect(std.mem.startsWith(u8, late, "Save /tmp/nonexistent-pardes-root/")); try testing.expect(std.mem.endsWith(u8, late, "/f.txt: no such directory")); diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig index 0fd75aa2..96f2a6bf 100644 --- a/core/ninep/pty.zig +++ b/core/ninep/pty.zig @@ -656,7 +656,7 @@ test "owned cwd pty exec rejects long paths before applying its batch" { const ctl = Node.of(pane.serial, .pty_ctl); var path: [1025]u8 = @splat('d'); path[0] = '/'; - p.setCwd(0, &path); + p.setCwd(.at(0), &path); for ([_][]const u8{ "exec\n", "winsize 100 30\nexec\n", "sig TERM\nexec\n" }) |command| { const result = wr(p, ctl, command); try testing.expectEqual(E.INVAL, result.errno()); @@ -664,7 +664,7 @@ test "owned cwd pty exec rejects long paths before applying its batch" { try testing.expect(result.signal == null and result.winsize == null); } try testing.expectEqualStrings(&path, pane.cwdSlice()); - p.setCwd(0, path[0..pardes.effect_path_cap]); + p.setCwd(.at(0), path[0..pardes.effect_path_cap]); const accepted = wr(p, ctl, "exec\n"); try testing.expectEqual(Status.ok, accepted.reply.status); try testing.expect(accepted.spawned); @@ -799,7 +799,7 @@ test "run answers how its command ended once the shell is back at a prompt" { try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = node, .handle = early.reply.handle, .size = 64 }).reply.status); try testing.expect(std.mem.endsWith(u8, rd(p, status, 0, 64).bytes, " 1\n")); // A respawn before that prompt keeps it waiting for the new shell's. - p.acknowledgeShell(0, "/bin/sh", true); + p.acknowledgeShell(.at(0), "/bin/sh", true); try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = node, .handle = early.reply.handle, .size = 64 }).reply.status); p.update(.{ .output = .{ .pane = 0, .bytes = prompt } }); var sent_late: [16]u8 = undefined; @@ -1114,7 +1114,7 @@ test "a terminal's ctl counts its body, and a new directory is a rename in the l const f = call(p, .{ .tag = 4, .op = .open, .node = log }).reply.handle; const frozen = call(p, .{ .tag = 5, .op = .read, .node = log, .handle = f, .size = 1 << 16 }).bytes.len; _ = call(p, .{ .tag = 6, .op = .write, .node = log, .handle = f, .data = "follow" }); - p.setCwd(0, "/somewhere/else"); + p.setCwd(.at(0), "/somewhere/else"); var want: [64]u8 = undefined; try testing.expectEqualStrings( try std.fmt.bufPrint(&want, "rename {d} /somewhere/else\n", .{serial}), |
