summaryrefslogtreecommitdiff
path: root/core/fs.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 10:49:23 -0300
committerGabriel Schneider <[email protected]>2026-11-19 11:41:14 -0300
commit4569aefd55d04f434f2e2ed5e6e4a511a414cdc7 (patch)
tree53bbb915ea64c0ddcf93f7f61d25c33071ff2427 /core/fs.zig
parent70c1aed30c6884024ecc2bd7f82d47e371d58ca4 (diff)
downloadpardes-4569aefd55d04f434f2e2ed5e6e4a511a414cdc7.tar.gz
pardes-4569aefd55d04f434f2e2ed5e6e4a511a414cdc7.zip
fs: the file system's sites are read through the tape a step is handed, and the reads no tape saw are listed (the handle's step 2, P20, pardes-handle-sizing's second noun): every site of core/fs.zig is the handle's, the core's (`p.tape`: /os's stat, listing and read, a mount's read) where a function holds the core, else a `tape: *Tape` parameter, taken by 16 functions (fs.makeDirs, expandHome, expandHomeFrom, resolveOs, readFile, readFileLimit, readRestore, restorePath; exec.kindOf; up to a core: dump.directory, restoreFile, onDisk, Db.statePath, Core.recentKeeps, Core.parentTrouble, config.Runtime.apply); fs.resolve takes its optional core's tape, `none` without one; sam's World carries the session's tape for `~user`; the bodies of make_dirs, read_file and kind take Zig's io from the tape, and /os's stat and listing are handed it, so fs.zig and exec.zig read the process's io nowhere; the finding, what stopped compiling for want of an io: fs.readHost's two direct callers, both host halves (the tape's own read by path of a record sent by hash, which takes its tape's io; a client's join reading a plain kind's file through the walk's dump hook, whose mode `join_files` is now the host's io), and by reading one step's read no tape saw, ninep/ctl.zig's bare deniedAbove in a /pager open (served in serveFs, which a client replays), now taped as its neighbours are (`p.tape.value(.denied, ..)`, no new site); the host's own calls of these (the launcher, a -l dump, fonts, theme files, Upgrade, a dump failure's message, gui tests) pass `&tape.none`, recorded by nobody as before; and the replay's dump check now puts the core's tape aside with `on` (its dump's `onDisk` replayed a site the tape did not have: every --replay seed diverged at its end in the first gate). The five numbers: (1) functions that gained the parameter 16 (row: 19 + 7); (2) perfops 97 counts within 0.1%, largest image-frame on small +0.0295%, none on a per-row path gained it; (3) stopped compiling for want of an io: fs.readHost from tape.byHash and from dump.slotWrite (host halves), osHandle's io local (fed only sites); (4) global io uses 6 (10), calls into the free functions 80 (92), machine_lines fs.zig 39 -> 38, exec.zig 4 -> 3; (5) lines changed: tests 33, code about 130 (20 of them in host files). Lines in files not this work's: dev/tui/tui.zig 990, dev/gui/gui.zig 613 629 1054 3057 6171 6264 7494 8290, dev/file_watch.zig 612 644, dev/host_io.zig 1521, runtime/main.zig 1373 1391 1398, runtime/macos.zig 646 668, runtime/upgrade.zig 349 396 (each one argument). Gate: tui core-test 837/980 (143 skipped), shell-test 1015/1018, pane-test 183/184, behaviour-test 275/275 and --replay 20 seeds 0 failures, process-test lspcomplete and lspcompletemoved (the base's; pagercolor flaked once, passed alone three of three), replicas --clients 5 diverged 0, unequal 0, deltas wrong 0 (1731/0, 1620/0, 1737/0), quiet 545/0, 554/0, 651/0; daemon.py plain, --far, --games, --window-clients pass; semantics 2f615168fe07b35f (unmoved); frames 77/77 byte-identical in Debug, gui unit-test 1613/1617, perfab corpus2x +0.057% pictures identical in all 10 runs, perfops PASS
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/fs.zig')
-rw-r--r--core/fs.zig105
1 files changed, 54 insertions, 51 deletions
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 {