Skip to content

Commit 76029e0

Browse files
feat: add file watching module
1 parent 4bfe5af commit 76029e0

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/file_watcher.zig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const STD = @import("std");
2+
3+
const WATCH_POLLING_RATE_MS: u64 = 500;
4+
5+
pub const FileWatcher = struct {
6+
const Self = @This();
7+
8+
current_file_path: []const u8 = "",
9+
previous_mod_time: i128 = 0,
10+
11+
pub fn init(file_path: []const u8) Self {
12+
return Self{
13+
.current_file_path = file_path,
14+
};
15+
}
16+
17+
pub fn checkForChanges(self: *Self) !bool {
18+
const metadata = try STD.fs.cwd().statFile(self.current_file_path);
19+
const current_mod_time = metadata.mtime;
20+
21+
if (current_mod_time != self.previous_mod_time) {
22+
self.previous_mod_time = current_mod_time;
23+
return true;
24+
}
25+
26+
return false;
27+
}
28+
};

0 commit comments

Comments
 (0)