summaryrefslogtreecommitdiff
path: root/src/fs.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs.zig')
-rw-r--r--src/fs.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/fs.zig b/src/fs.zig
index 47ee0856..dab7c8dd 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -738,6 +738,8 @@ pub fn readHost(gpa: std.mem.Allocator, path_z: [:0]const u8, limit: usize) ![]u
else => error.OpenFailed,
};
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;
// A device (/dev/zero, a tty) is no file to read whole: said so, not
// read to the stream limit and called too large.
@@ -791,9 +793,20 @@ pub fn readHost(gpa: std.mem.Allocator, path_z: [:0]const u8, limit: usize) ![]u
len += @intCast(n);
}
if (len != buf.len) buf = try gpa.realloc(buf, len);
+ if (before) |st| if (st.kind == .file) {
+ last_reads[last_read % last_reads.len] = .{ .path = std.hash.Wyhash.hash(0, path_z), .bytes = buf.ptr, .len = buf.len, .file = .{ .inode = st.inode, .size = st.size, .mtime_ns = st.mtime.nanoseconds, .ctime_ns = st.ctime.nanoseconds } };
+ last_read +%= 1;
+ };
return buf;
}
+/// The last files `readHost` read whole, each its path's hash, the buffer
+/// it returned and what the file was before the read: a watch armed over a
+/// text whose content is that very buffer (file_watch.applyEffect) finds the
+/// disk the same without reading it again.
+pub var last_reads: [8]struct { path: u64 = 0, bytes: [*]const u8 = undefined, len: usize = 0, file: @import("file_watch.zig").Identity = undefined } = @splat(.{});
+var last_read: usize = 0;
+
/// A 9P write of an Edit held while its commands run (Namespace.edit_hold).
pub const EditHold = struct {
/// The listener's: the connection that asked, and its park.