refactor: get zine watcher to build in flow

This commit is contained in:
CJ van den Berg 2025-11-30 15:03:14 +01:00
parent db4e3e1936
commit b698fffd25
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
7 changed files with 90 additions and 30 deletions

View file

@ -1,8 +1,8 @@
const LinuxWatcher = @This();
const std = @import("std");
const fatal = @import("../../../fatal.zig");
const Debouncer = @import("../../serve.zig").Debouncer;
const Debouncer = @import("Debouncer.zig");
const Error = @import("root.zig").Error;
const Allocator = std.mem.Allocator;
const log = std.log.scoped(.watcher);
@ -30,11 +30,7 @@ pub fn init(
gpa: std.mem.Allocator,
debouncer: *Debouncer,
dir_paths: []const []const u8,
) LinuxWatcher {
errdefer |err| fatal.msg("error: unable to start the file watcher: {s}", .{
@errorName(err),
});
) Error!LinuxWatcher {
const notify_fd = try std.posix.inotify_init1(0);
var watcher: LinuxWatcher = .{
.gpa = gpa,
@ -300,7 +296,7 @@ pub fn listen(watcher: *LinuxWatcher) !void {
var event_data = buffer[0..len];
while (event_data.len > 0) {
const event: *Event = @alignCast(@ptrCast(event_data[0..event_size]));
const event: *Event = @ptrCast(@alignCast(event_data[0..event_size]));
const parent = watcher.watch_fds.get(event.wd).?;
event_data = event_data[event_size + event.len ..];