summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Core.zig16
-rw-r--r--core/Db.zig6
-rw-r--r--core/Effect.zig2
-rw-r--r--core/Jump.zig2
-rw-r--r--core/Output.zig2
-rw-r--r--core/Plumb.zig2
-rw-r--r--core/Query.zig2
-rw-r--r--core/builtins.zig14
-rw-r--r--core/config.zig36
-rw-r--r--core/dump.zig41
-rw-r--r--core/edit_cmd.zig10
-rw-r--r--core/exec.zig16
-rw-r--r--core/fs.zig105
-rw-r--r--core/hunks.zig2
-rw-r--r--core/look.zig4
-rw-r--r--core/ninep/ctl.zig10
-rw-r--r--core/ninep/pane.zig4
-rw-r--r--core/root.zig4
-rw-r--r--core/sam_edit.zig4
-rw-r--r--core/tape.zig5
20 files changed, 149 insertions, 138 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 5bb0809e..3876b3e8 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -715,9 +715,9 @@ pub fn loadRecent(p: *Pardes) void {
/// Whether `path` is one Recent keeps: a file on this host's disk, not
/// the served tree's (`/virtual/`) nor a name never saved.
-pub fn recentKeeps(path: []const u8) bool {
+pub fn recentKeeps(tape: *pardes.tape.Tape, path: []const u8) bool {
const local = filesystem.localPath(path) orelse return false;
- return exec.kindOf(local) == .file;
+ return exec.kindOf(tape, local) == .file;
}
/// A file pane or a kind's (a PDF, a picture) closing: its place noted in Recent, when
@@ -1397,12 +1397,12 @@ fn missingInterpreter(bin: []const u8, out: []u8) ?[]const u8 {
/// The directory a write of `path` that failed with `err` went into:
/// what is there (a directory when it is no local path), whether it is
/// missing, and whether that is because one above refuses (EACCES).
-fn parentTrouble(path: []const u8, err: anyerror) struct { dir: []const u8, kind: ?std.Io.File.Kind, missing: bool, denied: bool } {
+fn parentTrouble(tape: *pardes.tape.Tape, path: []const u8, err: anyerror) struct { dir: []const u8, kind: ?std.Io.File.Kind, missing: bool, denied: bool } {
const dir = std.Io.Dir.path.dirname(path) orelse "/";
const local = filesystem.localPath(dir);
- const kind: ?std.Io.File.Kind = if (local) |l| exec.kindOf(l) else .directory;
+ const kind: ?std.Io.File.Kind = if (local) |l| exec.kindOf(tape, l) else .directory;
const missing = err == error.FileNotFound or err == error.NotDir or kind != .directory;
- const denied = missing and (if (local) |l| pardes.tape.value(.denied, filesystem.deniedAbove, .{l}) else false);
+ const denied = missing and (if (local) |l| tape.value(.denied, filesystem.deniedAbove, .{l}) else false);
return .{ .dir = dir, .kind = kind, .missing = missing, .denied = denied };
}
@@ -1416,7 +1416,7 @@ pub fn saveFailed(p: *Pardes, id: u8, path: []const u8, err: anyerror) void {
var what: pardes.Kind.Buf(limits.host_path_cap + 32) = .{};
// A write into a directory that is not there: said so, in the words
// a mount reads as ENOENT; EACCES when one above refuses.
- const parent = parentTrouble(path, err);
+ const parent = parentTrouble(p.tape, path, err);
if (parent.denied)
p.reportFailure(id, what.print("Save {s}: permission denied", .{path[0..@min(path.len, limits.host_path_cap)]}))
else if (parent.missing)
@@ -1437,7 +1437,7 @@ pub fn dumpFailed(p: *Pardes, path: []const u8, err: anyerror) void {
const operation = std.fmt.bufPrint(&what, "Dump {s}", .{path[0..@min(path.len, limits.host_path_cap)]}) catch unreachable; // cap + 5 fits cap + 8
// Into a DumpDir that is not there: said so, ENOENT, as a Save is;
// one that is there but no directory (`/dev/null`) says that.
- const parent = parentTrouble(path, err);
+ const parent = parentTrouble(p.tape, path, err);
var said: pardes.Kind.Buf(limits.host_path_cap + 48) = .{};
if (parent.denied and parent.kind == null)
p.reportFailure(v.active, said.print("{s}: permission denied", .{operation}))
@@ -1792,7 +1792,7 @@ pub fn sessionShell(p: *const Pardes) []const u8 {
/// A path's leading `~` (alone, or before `/` or `:`) as the session's home;
/// `~user` that user's (fs.expandHomeFrom).
pub fn expandHome(p: *const Pardes, path: []const u8, out: *[4096]u8) []const u8 {
- return filesystem.expandHomeFrom(path, out, p.sessionHome());
+ return filesystem.expandHomeFrom(p.tape, path, out, p.sessionHome());
}
/// The session's home, null for none.
diff --git a/core/Db.zig b/core/Db.zig
index e8d606ec..cbeee5fb 100644
--- a/core/Db.zig
+++ b/core/Db.zig
@@ -89,9 +89,9 @@ pub fn deinit(db: *Db) void {
/// The state file's path for the DumpDir setting `dir_setting`, made in
/// `buf`; null with no home to keep it in.
-pub fn statePath(buf: []u8, dir_setting: []const u8) ?[]const u8 {
+pub fn statePath(tape: *pardes.tape.Tape, buf: []u8, dir_setting: []const u8) ?[]const u8 {
var dir_buf: [4096]u8 = undefined;
- const dir = pardes.dump.directory(&dir_buf, dir_setting) orelse return null;
+ const dir = pardes.dump.directory(tape, &dir_buf, dir_setting) orelse return null;
return std.fmt.bufPrint(buf, "{s}/" ++ file_name, .{dir}) catch null;
}
@@ -1126,7 +1126,7 @@ fn opened(db: *Db, p: *Pardes) ?*Open {
.off => return null,
.disk => {
var buf: [4200]u8 = undefined;
- const path = statePath(&buf, p.settings.dump_dir.get()) orelse return null;
+ const path = statePath(p.tape, &buf, p.settings.dump_dir.get()) orelse return null;
if (db.open) |o| {
// The same file still: another session's compaction renames
// a new one over it, which this one then opens.
diff --git a/core/Effect.zig b/core/Effect.zig
index 4d2009fb..dad2979c 100644
--- a/core/Effect.zig
+++ b/core/Effect.zig
@@ -280,7 +280,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: []
// A Save makes the directories its file goes in, and any above them,
// first: one rule, for the pane's own name and `Save path` alike. A
// directory it cannot make leaves the write to fail and say why.
- if (filesystem.localPath(path)) |local| filesystem.makeDirs(std.Io.Dir.path.dirname(local) orelse "/");
+ if (filesystem.localPath(path)) |local| filesystem.makeDirs(p.tape, std.Io.Dir.path.dirname(local) orelse "/");
// The in-process filesystem reports the same way a real host does,
// so an OOM there leaves the pane dirty rather than looking saved.
if (p.host.vtable.write_file) |f| f(p.host.ctx, id, path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(id, path, error.OutOfMemory);
diff --git a/core/Jump.zig b/core/Jump.zig
index 3b8c8d01..6d12495e 100644
--- a/core/Jump.zig
+++ b/core/Jump.zig
@@ -296,7 +296,7 @@ pub fn jumpBy(p: *Pardes, delta: i32) void {
// Deleted since, or Recent has forgotten it: its entries go (the
// first said), and the step goes on to the next place, never
// stuck on one that cannot open.
- if (found == null or !Pardes.recentKeeps(found.?.path)) {
+ if (found == null or !Pardes.recentKeeps(p.tape, found.?.path)) {
var said: Kind.Buf(recent_path_cap + 32) = .{};
if (found) |e| p.setMessage(v.active, said.print("{s}: deleted, skipped", .{e.path[0..@min(e.path.len, recent_path_cap)]}));
const hash = j.path_hash;
diff --git a/core/Output.zig b/core/Output.zig
index 42341002..1395b06f 100644
--- a/core/Output.zig
+++ b/core/Output.zig
@@ -601,7 +601,7 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void {
const own = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice();
// Its directory gone (or never there, a name not yet saved): the list
// goes in the session's, where a look from it can still resolve.
- const dir = if (pardes.filesystem.localPath(own)) |local| (if (exec.kindOf(local) == .directory) own else p.sessionDir()) else own;
+ const dir = if (pardes.filesystem.localPath(own)) |local| (if (exec.kindOf(p.tape, local) == .directory) own else p.sessionDir()) else own;
const free = p.freeSlot() orelse return p.gpa.free(content);
_ = open(p, free, dir, .unsaved, "", content) catch |err| return p.reportError(id, "+Unsaved", err);
layout.placeNew(p, id, id, free, .doc);
diff --git a/core/Plumb.zig b/core/Plumb.zig
index 89f1a52d..a28ba5a8 100644
--- a/core/Plumb.zig
+++ b/core/Plumb.zig
@@ -477,7 +477,7 @@ const Parser = struct {
var buf: [4096]u8 = undefined;
const p = ps.p orelse return ps.fail("can't open {s} for inclusion", .{name});
const path = if (name[0] == '/') name else std.fmt.bufPrint(&buf, "{s}/{s}", .{ p.configDir() orelse "", name }) catch name;
- break :text fs.readFile(ps.arena, path) catch return ps.fail("can't open {s} for inclusion", .{path});
+ break :text fs.readFile(p.tape, ps.arena, path) catch return ps.fail("can't open {s} for inclusion", .{path});
};
const file = ps.file;
const line = ps.line;
diff --git a/core/Query.zig b/core/Query.zig
index 30b07e92..e8011a1f 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -1667,7 +1667,7 @@ fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void
const pane = p.panes[id].?;
const f = &pane.file.?;
if (!std.mem.eql(u8, f.path, path)) {
- if (exec.kindOf(path)) |kind| if (kind != .file) return;
+ if (exec.kindOf(p.tape, path)) |kind| if (kind != .file) return;
const bytes = pardes.tape.site(.preview, p.gpa, filesystem.read, .{ p, path }) catch return;
if (std.mem.indexOfScalar(u8, bytes[0..@min(bytes.len, 8000)], 0) != null) {
p.gpa.free(bytes);
diff --git a/core/builtins.zig b/core/builtins.zig
index 6b291628..a79e4b66 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -493,7 +493,7 @@ pub const Restore = struct {
// name. Else a label of the state file's.
var full_buf: [4096]u8 = undefined;
var label_buf: [256]u8 = undefined;
- const file = if (typed) |t| dump.restoreFile(t, c.p.settings.dump_dir.get(), &full_buf) else null;
+ const file = if (typed) |t| dump.restoreFile(c.p.tape, t, c.p.settings.dump_dir.get(), &full_buf) else null;
const name = if (file) |path| path else pardes.tape.authority(pardes.Db.labelled, .{ &c.p.db, c.p, typed, @as([]u8, &label_buf) }) orelse {
var buf: pardes.Kind.Buf(320) = .{};
return c.p.reportFailure(c.id, if (typed) |t| buf.print("Restore: no dump labelled {s}", .{t}) else "Restore: no dump yet; name one");
@@ -503,7 +503,7 @@ pub const Restore = struct {
// the host reads it only after this step, where nobody hears.
// First, so a Restore that could never happen spends no warning.
if (file) |path| {
- const bytes = @import("fs.zig").readFile(c.p.gpa, path) catch |err| {
+ const bytes = @import("fs.zig").readFile(c.p.tape, c.p.gpa, path) catch |err| {
var buf: pardes.Kind.Buf(limits.host_path_cap + 160) = .{};
var words: [128]u8 = undefined;
const why = switch (err) {
@@ -583,7 +583,7 @@ pub const Mount = struct {
// A socket path that is not there: said so (ENOENT), not a dial
// that went unanswered.
const sock_path: ?[]const u8 = if (std.mem.startsWith(u8, dial, "unix!")) dial[5..] else if (dial.len > 0 and dial[0] == '/') dial else null;
- if (sock_path) |path| if (@import("exec.zig").kindOf(path) == null) {
+ if (sock_path) |path| if (@import("exec.zig").kindOf(c.p.tape, path) == null) {
if (c.p.fs.mounts.pop()) |gone| {
c.p.gpa.free(gone.name);
c.p.gpa.free(gone.dial);
@@ -850,7 +850,7 @@ pub const Get = struct {
// edits are asked about: there would be nothing to load over them.
if (typed.len > 0) if (@import("fs.zig").localPath(path)) |local| {
var said: pardes.Kind.Buf(320) = .{};
- const kind = exec.kindOf(local);
+ const kind = exec.kindOf(c.p.tape, local);
if (kind == null or kind.? == .directory)
return c.p.reportFailure(c.id, said.print("Get: {s}: {s}", .{ path[0..@min(path.len, 256)], if (kind == null) "no such file" else "is a directory" }));
};
@@ -909,8 +909,8 @@ pub const Incl = struct {
return p.reportFailure(c.id, said.print("Incl: invalid directory: {s} is relative", .{shown}));
var home_buf: [4096]u8 = undefined;
const expanded = p.expandHome(dir_word, &home_buf);
- if (@import("fs.zig").localPath(expanded)) |local| if (exec.kindOf(local) != .directory)
- return p.reportFailure(c.id, if (exec.kindOf(local) != null)
+ if (@import("fs.zig").localPath(expanded)) |local| if (exec.kindOf(p.tape, local) != .directory)
+ return p.reportFailure(c.id, if (exec.kindOf(p.tape, local) != null)
said.print("Incl: not a directory: {s}", .{shown})
else
said.print("Incl: no such directory: {s}", .{shown}));
@@ -1321,7 +1321,7 @@ pub const Config = struct {
/// directory.
fn openConfigFile(c: Ctx, name: []const u8, path: []const u8, initial: []const u8) void {
var real_buf: [4096]u8 = undefined;
- const real = if (pardes.filesystem.resolveOs(path, &real_buf)) |r| r.path else null;
+ const real = if (pardes.filesystem.resolveOs(c.p.tape, path, &real_buf)) |r| r.path else null;
for (c.p.panes, 0..) |slot, id| {
const pane = slot orelse continue;
const f = pane.file orelse continue;
diff --git a/core/config.zig b/core/config.zig
index f1e2a239..792a7e62 100644
--- a/core/config.zig
+++ b/core/config.zig
@@ -834,7 +834,7 @@ pub const Runtime = struct {
}
/// `home`: what `~` is (the session's: Pardes.session_home).
- pub fn apply(state: *Runtime, setting: Setting, argument: ?[]const u8, home: ?[]const u8) bool {
+ pub fn apply(state: *Runtime, tape: *pardes.tape.Tape, setting: Setting, argument: ?[]const u8, home: ?[]const u8) bool {
switch (setting.action) {
// Every toggle names a bool field of its own, so one line covers
// all of them and a new toggle needs no arm here. Bare, a toggle
@@ -868,7 +868,7 @@ pub const Runtime = struct {
var home_buf: [4096]u8 = undefined;
// The session's disk's answer, as a failed save's (Core.zig):
// a client's replay takes it, never its own disk's.
- if (pardes.tape.value(.denied, pardes.filesystem.deniedAbove, .{pardes.filesystem.expandHomeFrom(text, &home_buf, home)})) return false;
+ if (tape.value(.denied, pardes.filesystem.deniedAbove, .{pardes.filesystem.expandHomeFrom(tape, text, &home_buf, home)})) return false;
}
if (!state.dump_dir.set(text)) return false;
},
@@ -1072,28 +1072,28 @@ pub const Runtime = struct {
const verbose = find("Verbose").?;
try std.testing.expect(state.verbose);
// Bare, it flips: that is what a tagline word does.
- try std.testing.expect(apply(&state, verbose, null, null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, verbose, null, null));
try std.testing.expect(!state.verbose);
// Told, it SETS -- twice over, so the second call proves it is not
// flipping past the value it was given.
- try std.testing.expect(apply(&state, verbose, "on", null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, verbose, "on", null));
try std.testing.expect(state.verbose);
- try std.testing.expect(apply(&state, verbose, " on\n", null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, verbose, " on\n", null));
try std.testing.expect(state.verbose);
- try std.testing.expect(apply(&state, verbose, "off", null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, verbose, "off", null));
try std.testing.expect(!state.verbose);
- try std.testing.expect(apply(&state, verbose, "off", null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, verbose, "off", null));
try std.testing.expect(!state.verbose);
// And anything else is refused rather than silently flipping.
- try std.testing.expect(!apply(&state, verbose, "maybe", null));
+ try std.testing.expect(!apply(&state, &pardes.tape.none, verbose, "maybe", null));
try std.testing.expect(!state.verbose);
}
test "simple setting application mutates only its plain field" {
var state: Runtime = .{};
- try std.testing.expect(apply(&state, find("Wrap").?, null, null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, find("Wrap").?, null, null));
try std.testing.expect(!state.wrap);
- try std.testing.expect(apply(&state, find("Shell").?, " fish\n", null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, find("Shell").?, " fish\n", null));
try std.testing.expectEqualStrings("fish", state.shell.requested.get());
try std.testing.expect(state.shell.pending);
}
@@ -1103,13 +1103,13 @@ pub const Runtime = struct {
var state: Runtime = .{};
for ([_][]const u8{ "1", " 82\n", "100" }) |argument| {
- try std.testing.expect(apply(&state, setting, argument, null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, setting, argument, null));
try std.testing.expectEqual(try std.fmt.parseInt(u8, std.mem.trim(u8, argument, " \t\r\n"), 10), state.font.tagline_percent);
}
state.font.tagline_percent = 67;
for ([_]?[]const u8{ null, "", "0", "101", "-1", "50%", "999999999999999999999" }) |argument| {
- try std.testing.expect(!apply(&state, setting, argument, null));
+ try std.testing.expect(!apply(&state, &pardes.tape.none, setting, argument, null));
try std.testing.expectEqual(@as(u8, 67), state.font.tagline_percent);
}
}
@@ -1123,7 +1123,7 @@ pub const Runtime = struct {
for ([_][]const u8{ "0", " 85\n", "100" }, [_]u8{ 0, 85, 100 }) |argument, expected| {
state.window_opacity_pending = false;
- try std.testing.expect(apply(&state, setting, argument, null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, setting, argument, null));
try std.testing.expectEqual(expected, state.window_opacity);
try std.testing.expect(state.window_opacity_pending);
}
@@ -1131,12 +1131,12 @@ pub const Runtime = struct {
state.window_opacity = 85;
state.window_opacity_pending = false;
for ([_]?[]const u8{ null, "", " \t\n", "101", "-1", "+85", "85%", "0.5", "85.0", "85 20", "8_5", "0x55", "999999999999999999999" }) |argument| {
- try std.testing.expect(!apply(&state, setting, argument, null));
+ try std.testing.expect(!apply(&state, &pardes.tape.none, setting, argument, null));
try std.testing.expectEqual(@as(u8, 85), state.window_opacity);
try std.testing.expect(!state.window_opacity_pending);
}
// Reissuing the same request still asks the host to apply it again.
- try std.testing.expect(apply(&state, setting, "85", null));
+ try std.testing.expect(apply(&state, &pardes.tape.none, setting, "85", null));
try std.testing.expect(state.window_opacity_pending);
}
@@ -1192,7 +1192,7 @@ pub const Runtime = struct {
.{ "GripWidth", "200" }, .{ "InactiveDim", "35" },
.{ "CallstackDepth", "16" }, .{ "Tab", "8" },
};
- for (values) |v| try std.testing.expect(apply(&state, find(v[0]).?, v[1], null));
+ for (values) |v| try std.testing.expect(apply(&state, &pardes.tape.none, find(v[0]).?, v[1], null));
try std.testing.expect(state.font.requested_name.set("Wanted Mono"));
try std.testing.expect(state.font.requested_path.set("/fonts/wanted.ttf"));
state.font.requested_size_hundredths = 1850;
@@ -1841,11 +1841,11 @@ test "CallstackDepth is bounded and keeps the last valid runtime limit" {
var state: Runtime = .{};
try std.testing.expectEqual(@as(u8, 8), state.callstack_depth);
for ([_][]const u8{ "1", "8", "16", "64" }) |value| {
- try std.testing.expect(Runtime.apply(&state, Runtime.find("CallstackDepth").?, value, null));
+ try std.testing.expect(Runtime.apply(&state, &pardes.tape.none, Runtime.find("CallstackDepth").?, value, null));
try std.testing.expectEqual(try std.fmt.parseInt(u8, value, 10), state.callstack_depth);
}
for ([_][]const u8{ "0", "65", "256", "-1", "+8", "1_6", "eight", "" }) |value| {
- try std.testing.expect(!Runtime.apply(&state, Runtime.find("CallstackDepth").?, value, null));
+ try std.testing.expect(!Runtime.apply(&state, &pardes.tape.none, Runtime.find("CallstackDepth").?, value, null));
try std.testing.expectEqual(@as(u8, 64), state.callstack_depth);
}
}
diff --git a/core/dump.zig b/core/dump.zig
index a37f46b9..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;
@@ -691,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 ----
@@ -808,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);
@@ -944,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"));
}
diff --git a/core/edit_cmd.zig b/core/edit_cmd.zig
index a87fdfa2..495ec786 100644
--- a/core/edit_cmd.zig
+++ b/core/edit_cmd.zig
@@ -77,9 +77,9 @@ const World = struct {
if (std.mem.eql(u8, f.path, path)) return true;
}
const local = filesystem.localPath(path) orelse return true;
- if (@import("exec.zig").kindOf(local) == .directory) return said(bool, why, "B: {s} is a directory", .{path}) orelse false;
+ if (@import("exec.zig").kindOf(w.p.tape, local) == .directory) return said(bool, why, "B: {s} is a directory", .{path}) orelse false;
var buf: [4096]u8 = undefined;
- if (filesystem.resolveOs(local, &buf) == null) return said(bool, why, "B: {s}: no such file", .{path}) orelse false;
+ if (filesystem.resolveOs(w.p.tape, local, &buf) == null) return said(bool, why, "B: {s}: no such file", .{path}) orelse false;
return true;
}
@@ -92,7 +92,7 @@ const World = struct {
fn open(ctx: *anyopaque, path: []const u8, why: *sam.Why) ?sam.File {
const w: *World = @ptrCast(@alignCast(ctx));
const p = w.p;
- if (filesystem.localPath(path)) |local| if (@import("exec.zig").kindOf(local) == .directory)
+ if (filesystem.localPath(path)) |local| if (@import("exec.zig").kindOf(p.tape, local) == .directory)
return said(sam.File, why, "B: {s} is a directory", .{path});
// A look opens it, or finds it open, where a look would; the
// keyboard stays where the Edit ran.
@@ -112,7 +112,7 @@ const World = struct {
fn read(ctx: *anyopaque, arena: std.mem.Allocator, path: []const u8, why: *sam.Why) ?[]const u8 {
const w: *World = @ptrCast(@alignCast(ctx));
- if (filesystem.localPath(path)) |local| if (@import("exec.zig").kindOf(local) == .directory)
+ if (filesystem.localPath(path)) |local| if (@import("exec.zig").kindOf(w.p.tape, local) == .directory)
return said([]const u8, why, "{s} is a directory", .{path});
const bytes = filesystem.read(w.p, path) catch |err| {
// In the words Get says them (builtins.Get).
@@ -177,7 +177,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void {
var world: World = .{ .p = p, .from = id, .arena = arena };
var why: sam.Why = .{};
var text: pardes.Kind.Buf(260) = .{};
- const res = sam.run(arena, files.items, cur, command, .{ .ctx = &world, .check = World.check, .open = World.open, .read = World.read, .refuseGet = World.refuseGet, .home = p.sessionHome() }, &why) catch |err| switch (err) {
+ const res = sam.run(arena, files.items, cur, command, .{ .ctx = &world, .check = World.check, .open = World.open, .read = World.read, .refuseGet = World.refuseGet, .home = p.sessionHome(), .tape = p.tape }, &why) catch |err| switch (err) {
error.Edit => return p.reportFailure(id, text.print("Edit: {s}", .{why.text()})),
error.OutOfMemory => return p.reportError(id, "Edit", err),
};
diff --git a/core/exec.zig b/core/exec.zig
index 3f3b16a7..0e09e175 100644
--- a/core/exec.zig
+++ b/core/exec.zig
@@ -423,19 +423,19 @@ pub fn missingDir(p: *Pardes, dir: []const u8) bool {
// the shell would start: no command or terminal runs there, and none
// is made to say `exit 127`.
const local = @import("fs.zig").localPath(dir) orelse return std.mem.startsWith(u8, dir, "/n/");
- return kindOf(local) != .directory;
+ return kindOf(p.tape, local) != .directory;
}
/// What `path` is on this host, null when it is not there; the turn out
/// while it asks (it may be inside a mount this editor serves).
-pub fn kindOf(path: []const u8) ?std.Io.File.Kind {
+pub fn kindOf(tape: *pardes.tape.Tape, path: []const u8) ?std.Io.File.Kind {
var buf: [4096]u8 = undefined;
const z = std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0) catch return null;
- return pardes.tape.site(.kind, null, kindHost, .{z});
+ return tape.site(.kind, null, kindHost, .{z});
}
-fn kindHost(z: [:0]const u8) ?std.Io.File.Kind {
- const stat = @import("fs.zig").statPath(std.Io.Threaded.global_single_threaded.io(), z, .{}) catch return null;
+fn kindHost(io: std.Io, z: [:0]const u8) ?std.Io.File.Kind {
+ const stat = @import("fs.zig").statPath(io, z, .{}) catch return null;
return stat.kind;
}
@@ -1039,18 +1039,18 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
var text: pardes.Kind.Buf(340) = .{};
return p.reportFailure(v.active, text.print("Shell: {s}", .{refused}));
}
- if (!p.settings.apply(setting, want, p.sessionHome())) p.reportFailure(v.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?);
+ if (!p.settings.apply(p.tape, setting, want, p.sessionHome())) p.reportFailure(v.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?);
},
// Bare, each says its value, as acme's Tab says the width.
inline .tab, .callstack_depth => |_, tag| if (arg == null) {
var said: pardes.Kind.Buf(40) = .{};
return p.setMessage(v.active, said.print("{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) }));
- } else if (!p.settings.apply(setting, arg, p.sessionHome())) {
+ } else if (!p.settings.apply(p.tape, setting, arg, p.sessionHome())) {
var said: pardes.Kind.Buf(96) = .{};
p.reportFailure(v.active, said.print("{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? }));
},
// Said with what it takes: its words, its range.
- else => if (!p.settings.apply(setting, arg, p.sessionHome())) {
+ else => if (!p.settings.apply(p.tape, setting, arg, p.sessionHome())) {
var buf: [160]u8 = undefined;
var text: std.Io.Writer = .fixed(&buf);
// A list of values too long for the row is cut.
diff --git a/core/fs.zig b/core/fs.zig
index f58e108b..27c28c9a 100644
--- a/core/fs.zig
+++ b/core/fs.zig
@@ -166,8 +166,7 @@ pub fn osHandle(p: *pardes.Pardes, req: Req) Reply {
if (comptime !platform_has_fs) return Reply.fail(req.tag, E.NOENT);
const path = osPath(p, req.node) orelse return Reply.fail(req.tag, E.NOENT);
if (req.op == .release) return .{ .tag = req.tag };
- const io = std.Io.Threaded.global_single_threaded.io();
- const stat = pardes.tape.site(.os_stat, null, osStat, .{ io, path }) catch return Reply.fail(req.tag, E.NOENT);
+ const stat = p.tape.site(.os_stat, null, osStat, .{path}) catch return Reply.fail(req.tag, E.NOENT);
const attr: Reply.Attr = .{ .name = if (req.node == os_root) "os" else std.Io.Dir.path.basename(path), .node = req.node, .dir = stat.kind == .directory, .size = stat.size, .mode = if (stat.kind == .directory) 0o755 else 0o644, .mtime = stat.mtime };
switch (req.op) {
.getattr => return .{ .tag = req.tag, .attr = attr },
@@ -183,7 +182,7 @@ pub fn osHandle(p: *pardes.Pardes, req: Req) Reply {
var buf: [4096]u8 = undefined;
const joined = std.fmt.bufPrint(&buf, "{s}/{s}", .{ std.mem.trimEnd(u8, path, "/"), req.data }) catch return Reply.fail(req.tag, E.NOENT);
var normalized_buf: [4096]u8 = undefined;
- const normalized = resolveOs(joined, &normalized_buf) orelse return Reply.fail(req.tag, E.NOENT);
+ const normalized = resolveOs(p.tape, joined, &normalized_buf) orelse return Reply.fail(req.tag, E.NOENT);
const node = osNode(p, normalized.path) catch return Reply.fail(req.tag, E.NFILE);
return osHandle(p, .{ .tag = req.tag, .op = .getattr, .node = node });
},
@@ -191,7 +190,7 @@ pub fn osHandle(p: *pardes.Pardes, req: Req) Reply {
// Listed into a buffer of this request's own first; the shared
// reply buffer is another request's to use while the turn is out.
var listing: [16 * 1024]u8 = undefined;
- const listed = pardes.tape.site(.os_listing, null, osListing, .{ io, path, req.off, req.size, &listing }) catch |err|
+ const listed = p.tape.site(.os_listing, null, osListing, .{ path, req.off, req.size, &listing }) catch |err|
return Reply.fail(req.tag, if (err == error.NotDir) E.NOTDIR else E.IO);
const out = p.fs.stage(p.gpa);
out.appendSlice(p.gpa, listed) catch return Reply.fail(req.tag, E.NOMEM);
@@ -207,7 +206,7 @@ pub fn osHandle(p: *pardes.Pardes, req: Req) Reply {
var z: [4096]u8 = undefined;
const path_z = std.fmt.bufPrintSentinel(&z, "{s}", .{path}, 0) catch return Reply.fail(req.tag, E.NOENT);
var buf: [ninep_io.msize]u8 = undefined; // a read never asks for more than a frame
- const got = switch (pardes.tape.site(.os_rw, null, osReadWrite, .{ path_z, req, attr, &buf })) {
+ const got = switch (p.tape.site(.os_rw, null, osReadWrite, .{ path_z, req, attr, &buf })) {
.reply => |reply| return reply,
.read => |bytes| bytes,
};
@@ -242,7 +241,8 @@ fn osListing(io: std.Io, path: []const u8, off: u64, size: u32, listing: *[16 *
var buf: [4096]u8 = undefined;
const joined = std.fmt.bufPrint(&buf, "{s}/{s}", .{ std.mem.trimEnd(u8, path, "/"), entry.name }) catch continue;
var normalized_buf: [4096]u8 = undefined;
- const normalized = resolveOs(joined, &normalized_buf) orelse continue;
+ // Inside a site's body, out of the turn: nothing in it is taped.
+ const normalized = resolveOs(&pardes.tape.none, joined, &normalized_buf) orelse continue;
const child = dir.statFile(io, entry.name, .{}) catch continue;
if (skip > 0) {
skip -= 1;
@@ -306,14 +306,14 @@ pub fn statPath(io: std.Io, path: []const u8, options: std.Io.Dir.StatFileOption
/// Make `dir` and each directory above it that is missing, as `mkdir -p`
/// does: one already there is no failure. A failure shows at the open
/// that follows.
-pub fn makeDirs(dir: []const u8) void {
+pub fn makeDirs(tape: *pardes.tape.Tape, dir: []const u8) void {
if (comptime !platform_has_fs) return;
if (dir.len == 0) return;
- pardes.tape.site(.make_dirs, null, makeDirsHost, .{dir});
+ tape.site(.make_dirs, null, makeDirsHost, .{dir});
}
-fn makeDirsHost(dir: []const u8) void {
- _ = std.Io.Dir.cwd().createDirPathStatus(std.Io.Threaded.global_single_threaded.io(), dir, .fromMode(0o755)) catch {};
+fn makeDirsHost(io: std.Io, dir: []const u8) void {
+ _ = std.Io.Dir.cwd().createDirPathStatus(io, dir, .fromMode(0o755)) catch {};
}
/// Whether `dir` is not there to make because one above it refuses: its
@@ -339,6 +339,8 @@ pub fn localPath(path: []const u8) ?[]const u8 {
}
pub fn resolve(p: ?*pardes.Pardes, word: []const u8, cwd: []const u8, out: *[4096]u8) ?Resolved {
+ // The core's tape; none without a core (the launcher's, a test's).
+ const tape = if (p) |core| core.tape else &pardes.tape.none;
if (word.len == 0 or std.mem.indexOfScalar(u8, word, 0) != null) return null;
var joined_buf: [4096]u8 = undefined;
const joined = if (word[0] == '/') word else std.fmt.bufPrint(&joined_buf, "{s}/{s}", .{ cwd, word }) catch return null;
@@ -351,7 +353,7 @@ pub fn resolve(p: ?*pardes.Pardes, word: []const u8, cwd: []const u8, out: *[409
const path = if (cut < explicit.len) explicit[cut..] else "/";
if (std.mem.eql(u8, name, "os")) {
var native_buf: [4096]u8 = undefined;
- const native = resolveOs(path, &native_buf) orelse return null;
+ const native = resolveOs(tape, path, &native_buf) orelse return null;
return .{ .path = std.fmt.bufPrint(out, "/n/os{s}", .{native.path}) catch return null };
}
if (std.mem.eql(u8, name, "self")) return resolveVirtual(p, path, out);
@@ -368,7 +370,7 @@ pub fn resolve(p: ?*pardes.Pardes, word: []const u8, cwd: []const u8, out: *[409
}
if (std.mem.eql(u8, joined, "/virtual")) return resolveVirtual(p, "/", out);
if (std.mem.startsWith(u8, joined, "/virtual/")) return resolveVirtual(p, joined[8..], out);
- if (resolveOs(joined, out)) |found| return found;
+ if (resolveOs(tape, joined, out)) |found| return found;
if (resolveVirtual(p, joined, out)) |found| return found;
// `.`, `..` and `./x` name the pane's directory, never the served tree:
// with that directory gone they name nothing (`.` would be /virtual/).
@@ -398,14 +400,15 @@ pub fn dotRelative(word: []const u8) bool {
/// runs it through here: look (B3 and 9P), name, Save, ThemeFile, DumpDir,
/// Restore, a forwarded `pardes ~/x`. The path itself when there is no
/// `~` to expand, or no home for it.
-pub fn expandHome(path: []const u8, out: *[4096]u8) []const u8 {
+pub fn expandHome(tape: *pardes.tape.Tape, path: []const u8, out: *[4096]u8) []const u8 {
if (path.len == 0 or path[0] != '~') return path;
// Home as the session that recorded found it (core/tape.zig).
- return pardes.tape.value(.env, expandHomeHost, .{ path, out });
+ return tape.value(.env, expandHomeHost, .{ path, out });
}
fn expandHomeHost(path: []const u8, out: *[4096]u8) []const u8 {
- return expandHomeFrom(path, out, processHome());
+ // A site's body: nothing in it is taped.
+ return expandHomeFrom(&pardes.tape.none, path, out, processHome());
}
/// This process's home: $HOME, else its passwd entry's; null for none.
@@ -416,10 +419,10 @@ pub fn processHome() ?[]const u8 {
/// expandHome with the home given (null: none, `~` left as typed): a
/// session's (Pardes.expandHome), or this process's. `~user` is that
/// user's passwd entry, as the session that recorded found it.
-pub fn expandHomeFrom(path: []const u8, out: *[4096]u8, given: ?[]const u8) []const u8 {
+pub fn expandHomeFrom(tape: *pardes.tape.Tape, path: []const u8, out: *[4096]u8, given: ?[]const u8) []const u8 {
if (path.len == 0 or path[0] != '~') return path;
const end = std.mem.indexOfAny(u8, path, "/:") orelse path.len;
- const home = (if (end == 1) given else pardes.tape.value(.env, userHome, .{path[1..end]})) orelse return path;
+ const home = (if (end == 1) given else tape.value(.env, userHome, .{path[1..end]})) orelse return path;
const trimmed = std.mem.trimEnd(u8, home, "/");
const rest = path[end..];
if (trimmed.len == 0 and (rest.len == 0 or rest[0] != '/')) return std.fmt.bufPrint(out, "/{s}", .{rest}) catch path;
@@ -439,11 +442,11 @@ fn userHome(name: []const u8) ?[]const u8 {
return std.mem.span(pw.dir orelse return null);
}
-pub fn resolveOs(path: []const u8, out: *[4096]u8) ?Resolved {
+pub fn resolveOs(tape: *pardes.tape.Tape, path: []const u8, out: *[4096]u8) ?Resolved {
if (comptime !platform_has_fs) return null;
var z: [4096]u8 = undefined;
const path_z = std.fmt.bufPrintSentinel(&z, "{s}", .{path}, 0) catch return null;
- return pardes.tape.site(.resolve, null, resolveHost, .{ path_z, out });
+ return tape.site(.resolve, null, resolveHost, .{ path_z, out });
}
fn resolveHost(path_z: [:0]const u8, out: *[4096]u8) ?Resolved {
@@ -492,8 +495,8 @@ pub fn readLimit(p: *pardes.Pardes, path: []const u8, max_bytes: usize) ReadErro
const remote_path = if (cut < explicit.len) explicit[cut..] else "/";
if (std.mem.eql(u8, name, "os")) {
var native_buf: [4096]u8 = undefined;
- const native = resolveOs(remote_path, &native_buf) orelse return readFileLimit(p.gpa, path, limit);
- if (!native.dir) return readFileLimit(p.gpa, path, limit);
+ const native = resolveOs(p.tape, remote_path, &native_buf) orelse return readFileLimit(p.tape, p.gpa, path, limit);
+ if (!native.dir) return readFileLimit(p.tape, p.gpa, path, limit);
// The node stays in the table until no connection names it either
// (runtime/9p_io.zig, collectOs): a client may have walked to it too.
const node = try osNode(p, native.path);
@@ -507,7 +510,7 @@ pub fn readLimit(p: *pardes.Pardes, path: []const u8, max_bytes: usize) ReadErro
if (!std.mem.eql(u8, name, mount.name)) continue;
// A peer answers on its own time, and the peer may be this very
// editor: the turn goes out with the request.
- return pardes.tape.site(.read_mount, p.gpa, ninep_io.Client.readMount, .{ p.gpa, mount.dial, remote_path, path, limit });
+ return p.tape.site(.read_mount, p.gpa, ninep_io.Client.readMount, .{ p.gpa, mount.dial, remote_path, path, limit });
}
return error.FileNotFound;
}
@@ -515,7 +518,7 @@ pub fn readLimit(p: *pardes.Pardes, path: []const u8, max_bytes: usize) ReadErro
const name = path[9..];
if (tree.resolveSelf(p, name)) |node| return readNode(p, node, path, limit);
}
- return readFileLimit(p.gpa, path, limit);
+ return readFileLimit(p.tape, p.gpa, path, limit);
}
fn readNode(p: *pardes.Pardes, initial_node: u64, path: []const u8, limit: usize) ![]u8 {
@@ -682,39 +685,39 @@ fn isDir(path: [*:0]const u8) bool {
return true;
}
-pub fn readFile(gpa: std.mem.Allocator, path: []const u8) ![]u8 {
- return readFileLimit(gpa, path, limits.max_file_bytes);
+pub fn readFile(tape: *pardes.tape.Tape, gpa: std.mem.Allocator, path: []const u8) ![]u8 {
+ return readFileLimit(tape, gpa, path, limits.max_file_bytes);
}
/// The file a Restore of `typed` reads (restorePath), whole.
-pub fn readRestore(gpa: std.mem.Allocator, typed: []const u8, dir_setting: []const u8) ![]u8 {
+pub fn readRestore(tape: *pardes.tape.Tape, gpa: std.mem.Allocator, typed: []const u8, dir_setting: []const u8) ![]u8 {
var buf: [4096]u8 = undefined;
- return readFile(gpa, restorePath(typed, dir_setting, &buf));
+ return readFile(tape, gpa, restorePath(tape, typed, dir_setting, &buf));
}
/// The file a Restore of `typed` reads, whole: `~` expanded, a relative name
/// the DumpDir's when one is there, else the current directory's. What the
/// log and the message say, not the name as typed. `typed` itself (home
/// expanded) when nothing resolves: the read then says why.
-pub fn restorePath(typed: []const u8, dir_setting: []const u8, out: *[4096]u8) []const u8 {
+pub fn restorePath(tape: *pardes.tape.Tape, typed: []const u8, dir_setting: []const u8, out: *[4096]u8) []const u8 {
var home_buf: [4096]u8 = undefined;
- const path = expandHome(typed, &home_buf);
+ const path = expandHome(tape, typed, &home_buf);
if (!std.Io.Dir.path.isAbsolute(path)) {
var dir_buf: [4096]u8 = undefined;
- if (@import("dump.zig").directory(&dir_buf, dir_setting)) |base| {
+ if (@import("dump.zig").directory(tape, &dir_buf, dir_setting)) |base| {
var buf: [4096]u8 = undefined;
if (std.fmt.bufPrint(&buf, "{s}/{s}", .{ base, path })) |candidate| {
- if (resolveOs(candidate, out)) |r| if (!r.dir) return r.path;
+ if (resolveOs(tape, candidate, out)) |r| if (!r.dir) return r.path;
} else |_| {}
}
}
- if (resolveOs(path, out)) |r| return r.path;
+ if (resolveOs(tape, path, out)) |r| return r.path;
const n = @min(path.len, out.len);
@memcpy(out[0..n], path[0..n]);
return out[0..n];
}
-fn readFileLimit(gpa: std.mem.Allocator, path: []const u8, limit: usize) ![]u8 {
+fn readFileLimit(tape: *pardes.tape.Tape, gpa: std.mem.Allocator, path: []const u8, limit: usize) ![]u8 {
if (std.mem.indexOfScalar(u8, path, 0) != null) return error.OpenFailed;
if (!platform_has_fs or std.mem.startsWith(u8, path, "/virtual/")) {
const archive_path = if (std.mem.startsWith(u8, path, "/virtual/")) path[9..] else path;
@@ -729,12 +732,12 @@ fn readFileLimit(gpa: std.mem.Allocator, path: []const u8, limit: usize) ![]u8 {
const path_z = std.fmt.bufPrintSentinel(&pathbuf, "{s}", .{native}, 0) catch return error.PathTooLong;
// The path may be a mount this editor serves: the turn goes out with the
// syscalls, and the bytes come back into memory of the caller's own.
- return pardes.tape.site(.read_file, gpa, readHost, .{ gpa, path_z, limit });
+ return tape.site(.read_file, gpa, readHost, .{ gpa, path_z, limit });
}
/// The disk's file at `path_z`, whole: the session's read, and a replica
/// client's of a read it was sent by hash (tape.zig `byHash`).
-pub fn readHost(gpa: std.mem.Allocator, path_z: [:0]const u8, limit: usize) ![]u8 {
+pub fn readHost(io: std.Io, gpa: std.mem.Allocator, path_z: [:0]const u8, limit: usize) ![]u8 {
const fd = libc.open(path_z, .{ .ACCMODE = .RDONLY, .NONBLOCK = true });
if (fd < 0) return switch (libc.errno(fd)) {
.ACCES, .PERM => error.PermissionDenied,
@@ -745,7 +748,7 @@ pub fn readHost(gpa: std.mem.Allocator, path_z: [:0]const u8, limit: usize) ![]u
};
defer _ = libc.close(fd);
// What it is before its bytes are read, for a watch armed over them.
- const before = (std.Io.File{ .handle = fd, .flags = .{ .nonblocking = true } }).stat(std.Io.Threaded.global_single_threaded.io()) catch null;
+ const before = (std.Io.File{ .handle = fd, .flags = .{ .nonblocking = true } }).stat(io) catch null;
// A device (/dev/zero, a tty) is no file to read whole: said so, not
// read to the stream limit and called too large.
@@ -1280,10 +1283,10 @@ test "bounded reads apply the same limits to self bodies and embedded sources" {
try std.testing.expectEqualStrings(source.contents, bytes);
try std.testing.expectError(error.FileTooLarge, readLimit(p, path, source.contents.len - 1));
}
- const bytes = try readFileLimit(gpa, "/virtual/src/look.zig", source.contents.len);
+ const bytes = try readFileLimit(&pardes.tape.none, gpa, "/virtual/src/look.zig", source.contents.len);
defer gpa.free(bytes);
try std.testing.expectEqualStrings(source.contents, bytes);
- try std.testing.expectError(error.FileTooLarge, readFileLimit(gpa, "/virtual/src/look.zig", source.contents.len - 1));
+ try std.testing.expectError(error.FileTooLarge, readFileLimit(&pardes.tape.none, gpa, "/virtual/src/look.zig", source.contents.len - 1));
}
}
@@ -1336,7 +1339,7 @@ test "bounded reads probe size-unknown proc files at the exact limit" {
try std.testing.expect(expected.len > 0);
var storage: [256 * 1024]u8 = undefined;
var fixed = std.heap.FixedBufferAllocator.init(&storage);
- const bounded = try readFileLimit(fixed.allocator(), "/proc/version", limits.max_stream_bytes);
+ const bounded = try readFileLimit(&pardes.tape.none, fixed.allocator(), "/proc/version", limits.max_stream_bytes);
try std.testing.expectEqualStrings(expected, bounded);
fixed.allocator().free(bounded);
for ([_][]const u8{ "/proc/version", "/n/os/proc/version" }) |path| {
@@ -1385,7 +1388,7 @@ test "oversized OS files fail before allocating their contents" {
var path_buf: [4096]u8 = undefined;
const path_len = try tmp.dir.realPathFile(std.testing.io, "oversized", &path_buf);
var failing: std.testing.FailingAllocator = .init(std.testing.allocator, .{ .fail_index = 0 });
- try std.testing.expectError(error.FileTooLarge, readFile(failing.allocator(), path_buf[0..path_len]));
+ try std.testing.expectError(error.FileTooLarge, readFile(&pardes.tape.none, failing.allocator(), path_buf[0..path_len]));
try std.testing.expectEqual(@as(usize, 0), failing.allocations);
}
@@ -1465,16 +1468,16 @@ test "a leading ~ is home, from HOME or else the passwd entry" {
var out: [4096]u8 = undefined;
const home = homeDir(std.c.getenv("HOME")) orelse return error.SkipZigTest;
var want: [4096]u8 = undefined;
- try std.testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{s}/x:12", .{std.mem.trimEnd(u8, home, "/")}), expandHome("~/x:12", &out));
- try std.testing.expectEqualStrings(std.mem.trimEnd(u8, home, "/"), expandHome("~", &out));
- try std.testing.expectEqualStrings("a/~/b", expandHome("a/~/b", &out));
- try std.testing.expectEqualStrings("~no-such-user-pardes/x", expandHome("~no-such-user-pardes/x", &out));
- try std.testing.expectEqualStrings("/", expandHome("~root", &out)[0..1]);
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{s}/x:12", .{std.mem.trimEnd(u8, home, "/")}), expandHome(&pardes.tape.none, "~/x:12", &out));
+ try std.testing.expectEqualStrings(std.mem.trimEnd(u8, home, "/"), expandHome(&pardes.tape.none, "~", &out));
+ try std.testing.expectEqualStrings("a/~/b", expandHome(&pardes.tape.none, "a/~/b", &out));
+ try std.testing.expectEqualStrings("~no-such-user-pardes/x", expandHome(&pardes.tape.none, "~no-such-user-pardes/x", &out));
+ try std.testing.expectEqualStrings("/", expandHome(&pardes.tape.none, "~root", &out)[0..1]);
// HOME unset: the passwd entry's home.
const pw = std.c.getpwuid(std.c.getuid()) orelse return error.SkipZigTest;
var from_passwd: [4096]u8 = undefined;
- try std.testing.expectEqualStrings(try std.fmt.bufPrint(&from_passwd, "{s}/y", .{std.mem.trimEnd(u8, std.mem.span(pw.dir.?), "/")}), expandHomeFrom("~/y", &out, homeDir(null)));
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&from_passwd, "{s}/y", .{std.mem.trimEnd(u8, std.mem.span(pw.dir.?), "/")}), expandHomeFrom(&pardes.tape.none, "~/y", &out, homeDir(null)));
}
test "Restore prefers default directory then falls back to original path" {
@@ -1490,25 +1493,25 @@ test "Restore prefers default directory then falls back to original path" {
defer gpa.free(nested);
try tmp.dir.createDirPath(std.testing.io, nested);
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "dumps/a.dump", .data = "short name" });
- const short = try readRestore(gpa, "a.dump", base);
+ const short = try readRestore(&pardes.tape.none, gpa, "a.dump", base);
defer gpa.free(short);
try std.testing.expectEqualStrings("short name", short);
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.dump", .data = "original" });
- const fallback = try readRestore(gpa, relative, base);
+ const fallback = try readRestore(&pardes.tape.none, gpa, relative, base);
defer gpa.free(fallback);
try std.testing.expectEqualStrings("original", fallback);
const candidate = try std.fmt.allocPrint(gpa, "{s}/{s}", .{ base, relative });
defer gpa.free(candidate);
try writeFile(candidate, "default");
- const preferred = try readRestore(gpa, relative, base);
+ const preferred = try readRestore(&pardes.tape.none, gpa, relative, base);
defer gpa.free(preferred);
try std.testing.expectEqualStrings("default", preferred);
const absolute = try tmp.dir.realPathFileAlloc(std.testing.io, "a.dump", gpa);
defer gpa.free(absolute);
- const direct = try readRestore(gpa, absolute, base);
+ const direct = try readRestore(&pardes.tape.none, gpa, absolute, base);
defer gpa.free(direct);
try std.testing.expectEqualStrings("original", direct);
- try std.testing.expectError(error.FileNotFound, readRestore(gpa, "missing-restore-test.dump", base));
+ try std.testing.expectError(error.FileNotFound, readRestore(&pardes.tape.none, gpa, "missing-restore-test.dump", base));
}
test {
diff --git a/core/hunks.zig b/core/hunks.zig
index d3a8f5a7..a7d8e6cb 100644
--- a/core/hunks.zig
+++ b/core/hunks.zig
@@ -634,7 +634,7 @@ pub fn word(c: pardes.builtins.Ctx) void {
while (true) {
var buf: [4096]u8 = undefined;
const dot_git = std.fmt.bufPrint(&buf, "{s}/.git", .{dir}) catch return declined(p, c.id, "Diff: not in a git work tree");
- if (pardes.exec.kindOf(dot_git) != null) break;
+ if (pardes.exec.kindOf(p.tape, dot_git) != null) break;
dir = std.Io.Dir.path.dirname(dir) orelse return declined(p, c.id, "Diff: not in a git work tree");
}
// ponytail: a hex word that names no commit leaves git's error in a command pane, not a search; check the object first if that bites.
diff --git a/core/look.zig b/core/look.zig
index 170e5ea9..e075bbae 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -1032,7 +1032,7 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text:
if (filesystem.dotRelative(trimmed)) {
const dir = Pardes.paneDir(pane);
var said: Kind.Buf(4096 + 104) = .{};
- const gone = if (filesystem.localPath(dir)) |local| exec.kindOf(local) != .directory else false;
+ const gone = if (filesystem.localPath(dir)) |local| exec.kindOf(p.tape, local) != .directory else false;
if (gone) return p.reportFailure(id, said.print("look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}));
// A file not there is a miss, as `x` and `/abs/x` are: said and
// logged, the write answered with nothing.
@@ -1569,7 +1569,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
.dir => |dir| {
// A directory that is not there (the pane's own, gone): said,
// ENOENT, no terminal made in it.
- if (filesystem.localPath(dir)) |local| if (exec.kindOf(local) != .directory) {
+ if (filesystem.localPath(dir)) |local| if (exec.kindOf(p.tape, local) != .directory) {
var said: Kind.Buf(4096 + 104) = .{};
return p.reportFailure(id, said.print("look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}));
};
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig
index 81600582..a4f16597 100644
--- a/core/ninep/ctl.zig
+++ b/core/ninep/ctl.zig
@@ -571,7 +571,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
.callstack_depth => arg.len == 0 or (std.fmt.parseInt(u8, arg, 10) catch 0) -% 1 < pardes.lsp.callstack_max_depth,
else => probe: {
var probe = p.settings;
- break :probe probe.apply(setting, if (arg.len > 0) arg else null, p.sessionHome());
+ break :probe probe.apply(p.tape, setting, if (arg.len > 0) arg else null, p.sessionHome());
},
};
if (takes) return null;
@@ -679,13 +679,13 @@ pub fn writePager(p: *Pardes, req: Req) Reply {
}
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)
+ if (exec_line.kindOf(p.tape, local) != .directory) {
+ if (exec_line.kindOf(p.tape, 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 &p.fs.ename); // cut to ename's 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 &p.fs.ename); // cut to ename's 320
}
// Nor one that may not be written, as a file's name there is refused.
- if (pardes.filesystem.deniedAbove(local))
+ if (p.tape.value(.denied, 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 &p.fs.ename); // cut to ename's 320
};
const id = pardes.panes.Output.openPager(p, p.view().active, dir) catch |err|
@@ -773,7 +773,7 @@ pub fn writeRoot(p: *Pardes, req: Req) Reply {
if (!apply) continue;
// ponytail: read on the 9P task, a small local file; a big
// one would want pardes.turn's yield.
- const bytes = fs.readFile(p.gpa, path) catch |err| return refuseQuoting(p, req, @errorName(err), path, "");
+ const bytes = fs.readFile(p.tape, p.gpa, path) catch |err| return refuseQuoting(p, req, @errorName(err), path, "");
defer p.gpa.free(bytes);
_ = pardes.Handover.adopt(p, bytes) catch |err| return refuseQuoting(p, req, @errorName(err), path, "");
continue;
diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig
index 16d7762a..96a50703 100644
--- a/core/ninep/pane.zig
+++ b/core/ninep/pane.zig
@@ -900,7 +900,7 @@ fn writeName(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
// 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 (fs.localPath(full)) |local| exec.kindOf(p.tape, 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 &p.fs.ename); // cut to ename's 320
nameBuffer(p, id, full, false) catch |err| return Reply.fail(req.tag, switch (err) {
error.OutOfMemory => E.NOMEM,
@@ -944,7 +944,7 @@ pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) !
p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } });
events.noteLog(p, .rename, pane);
// A name given: whether a file there is on disk is the disk's to say.
- f.on_disk = f.output == null and pardes.Pardes.recentKeeps(f.path);
+ f.on_disk = f.output == null and pardes.Pardes.recentKeeps(p.tape, f.path);
if (f.on_disk) p.recent.opened(p.recentGpa(), f.path);
}
diff --git a/core/root.zig b/core/root.zig
index 53ee2ba2..706c833d 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -622,8 +622,8 @@ const machine_lines = [_]struct { []const u8, usize, []const u8 }{
.{ "dump.zig", 4, "a dump's clock and the state file's directory (XDG, the process's directory): the session's side (a client's Restore waits)" },
.{ "echo.zig", 1, "PARDES_REPLICA_TRACE: a trace" },
.{ "edit_cmd.zig", 1, "Edit's pipe environment (host_io.commandEnv): kept in Pipe.edit_run, `.authority` state, read only by the host's `pipe`, which a client never calls" },
- .{ "exec.zig", 4, "kindOf's stat (tape.site(.kind)) and Shell's check (tape.site(.shell))" },
- .{ "fs.zig", 39, "the file system behind the tape's sites (open, read, write, stat, mkdir, access), the process's home (read once at the start, taped), the 9P transport" },
+ .{ "exec.zig", 3, "kindOf's stat (tape.site(.kind), its io the tape's) and Shell's check (tape.site(.shell))" },
+ .{ "fs.zig", 38, "the file system behind the tape's sites (open, read, write, stat, mkdir, access; their io the tape's), the process's home (read once at the start, taped), the 9P transport" },
.{ "hunks.zig", 1, "a test helper's file read" },
.{ "look.zig", 6, "openLink's fork (the host's: a view's frontend opens a link) and a remote's error name" },
.{ "memory.zig", 7, "the memory regions themselves (mmap, madvise, their locks)" },
diff --git a/core/sam_edit.zig b/core/sam_edit.zig
index 4d7d6a27..0f4a70ba 100644
--- a/core/sam_edit.zig
+++ b/core/sam_edit.zig
@@ -85,6 +85,8 @@ pub const World = struct {
refuseGet: *const fn (ctx: *anyopaque, id: usize, why: *Why) bool,
/// What `~` is: the session's home (null: none).
home: ?[]const u8 = null,
+ /// The session's tape, which a `~user` read goes through (none: nobody's).
+ tape: *@import("tape.zig").Tape = &@import("tape.zig").none,
};
/// What an Edit came to: every file (those `B` opened after the ones it
@@ -670,7 +672,7 @@ const Exec = struct {
fn pathIn(ex: *Exec, fi: usize, name_in: []const u8) Failure![]const u8 {
// `~` and `~user` as Get, Incl and Save read them.
var home: [4096]u8 = undefined;
- const name = try ex.arena.dupe(u8, @import("fs.zig").expandHomeFrom(name_in, &home, if (ex.world) |w| w.home else null));
+ const name = try ex.arena.dupe(u8, @import("fs.zig").expandHomeFrom(if (ex.world) |w| w.tape else &@import("tape.zig").none, name_in, &home, if (ex.world) |w| w.home else null));
if (name.len > 0 and name[0] == '/') return name;
const dir = std.Io.Dir.path.dirnamePosix(ex.files.items[fi].name) orelse "/";
return std.Io.Dir.path.resolvePosix(ex.arena, &.{ dir, name });
diff --git a/core/tape.zig b/core/tape.zig
index 19fdccd1..dc80887c 100644
--- a/core/tape.zig
+++ b/core/tape.zig
@@ -475,7 +475,7 @@ pub const Tape = struct {
for (t.files.items) |f| if (std.mem.eql(u8, &f.hash, hash)) return f.bytes;
const path = t.reading orelse return null;
if (!t.local_files or !is_path) return null;
- const file = pardes.filesystem.readHost(t.gpa, path, pardes.memory.limits.max_file_bytes) catch return null;
+ const file = pardes.filesystem.readHost(t.io, t.gpa, path, pardes.memory.limits.max_file_bytes) catch return null;
defer t.gpa.free(file);
// The answer as `record` wrote it: an error union's yes, a length, the bytes.
const bytes = t.gpa.alloc(u8, 9 + file.len) catch return null;
@@ -607,6 +607,9 @@ pub const Tape = struct {
fn dumpRoundTrip(t: *Tape, p: *Pardes) void {
on = null;
defer on = t;
+ // The core's own tape aside too: the dump's reads are no input.
+ p.tape = &none;
+ defer p.tape = t;
const bytes = pardes.dump.dumpBytes(p) catch |err| return t.diverge("dump failed: {t}", .{err});
defer t.gpa.free(bytes);
var notes: std.ArrayList(u8) = .empty;