summaryrefslogtreecommitdiff
path: root/src/fs.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs.zig')
-rw-r--r--src/fs.zig16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/fs.zig b/src/fs.zig
index 4bbf09bb..733418da 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -171,8 +171,8 @@ pub fn osHandle(p: *pardes.Pardes, req: Req) Reply {
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, statPath, .{ io, path, std.Io.Dir.StatFileOptions{} }) catch return Reply.fail(req.tag, E.NOENT);
- const attr: Reply.Attr = .{ .name = if (req.node == os_root) "os" else std.fs.path.basename(path), .node = req.node, .dir = stat.kind == .directory, .size = stat.size, .mode = if (stat.kind == .directory) 0o755 else 0o644, .mtime = std.math.cast(u32, stat.mtime.toSeconds()) orelse 0 };
+ const stat = pardes.tape.site(.os_stat, null, osStat, .{ io, path }) catch return Reply.fail(req.tag, E.NOENT);
+ const attr: Reply.Attr = .{ .name = if (req.node == os_root) "os" else std.fs.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 },
.open => {
@@ -223,6 +223,16 @@ pub fn osHandle(p: *pardes.Pardes, req: Req) Reply {
}
}
+/// What /os keeps of a stat, as the tape carries it to a replica: the same
+/// bytes on every OS, which std.Io.File.Stat is not (a FreeBSD one's
+/// `nlink` and `permissions` are another width than a Linux one's).
+pub const OsStat = struct { kind: std.Io.File.Kind, size: u64, mtime: u32 };
+
+fn osStat(io: std.Io, path: []const u8) !OsStat {
+ const stat = try statPath(io, path, .{});
+ return .{ .kind = stat.kind, .size = stat.size, .mtime = std.math.cast(u32, stat.mtime.toSeconds()) orelse 0 };
+}
+
/// A directory's listing under /os, the entries from `off` until `size`
/// bytes of them are staged, into `listing`: the syscalls of a readdir.
fn osListing(io: std.Io, path: []const u8, off: u64, size: u32, listing: *[16 * 1024]u8) error{ NotDir, Io }![]const u8 {
@@ -249,7 +259,7 @@ fn osListing(io: std.Io, path: []const u8, off: u64, size: u32, listing: *[16 *
return listed.items;
}
-const OsReadWrite = union(enum) { reply: Reply, read: []const u8 };
+pub const OsReadWrite = union(enum) { reply: Reply, read: []const u8 };
/// The syscalls of an /os read, write or truncate: the reply, or the bytes
/// read into `buf`.