From bafa7d4b24cd7815a3fb504bef15b54d750e5577 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 15 Mar 2026 00:33:56 +0100 Subject: [PATCH] fix: minor clean-up --- src/backend/KQueue.zig | 2 +- src/backend/KQueueDir.zig | 2 +- src/nightwatch.zig | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backend/KQueue.zig b/src/backend/KQueue.zig index b59d2fd..a51a6d0 100644 --- a/src/backend/KQueue.zig +++ b/src/backend/KQueue.zig @@ -16,7 +16,7 @@ watches_mutex: std.Thread.Mutex, file_watches: std.StringHashMapUnmanaged(std.posix.fd_t), // owned file path -> fd file_watches_mutex: std.Thread.Mutex, // Per-directory snapshots of filenames, used to diff on NOTE_WRITE. -// Key: owned dir path (same as watches key), value: set of owned filenames. +// Key: independently owned dir path, value: set of owned filenames. // Accessed from both the main thread (add_watch) and the background thread (scan_dir). snapshots: std.StringHashMapUnmanaged(std.StringHashMapUnmanaged(void)), snapshots_mutex: std.Thread.Mutex, diff --git a/src/backend/KQueueDir.zig b/src/backend/KQueueDir.zig index 0449a5a..a7574e7 100644 --- a/src/backend/KQueueDir.zig +++ b/src/backend/KQueueDir.zig @@ -17,7 +17,7 @@ watches_mutex: std.Thread.Mutex, // Per-directory snapshots: owned filename -> mtime_ns. // Used to diff on NOTE_WRITE: detects creates, deletes, and (opportunistically) // modifications when the same directory fires another event later. -// Key: owned dir path (same as watches key), value: map of owned filename -> mtime_ns. +// Key: independently owned dir path, value: map of owned filename -> mtime_ns. snapshots: std.StringHashMapUnmanaged(std.StringHashMapUnmanaged(i128)), snapshots_mutex: std.Thread.Mutex, diff --git a/src/nightwatch.zig b/src/nightwatch.zig index 04e68c9..d0a20cc 100644 --- a/src/nightwatch.zig +++ b/src/nightwatch.zig @@ -191,7 +191,13 @@ pub fn Create(comptime variant: Variant) type { /// was never watched. Does not unwatch subdirectories that were /// added automatically as a result of watching `path`. pub fn unwatch(self: *@This(), path: []const u8) UnwatchError!void { - return self.interceptor.backend.remove_watch(self.allocator, path); + // Normalize path the same way watch() does so that relative or + // dot-containing paths resolve to the same key that was stored. + const norm = std.fs.path.resolve(self.allocator, &.{path}) catch { + return; // OOM: treat as no-op; path was never watched under the resolved form + }; + defer self.allocator.free(norm); + return self.interceptor.backend.remove_watch(self.allocator, norm); } /// Read pending events from the backend fd and deliver them to the handler.