fix: minor clean-up

This commit is contained in:
CJ van den Berg 2026-03-15 00:33:56 +01:00
parent 4339c122eb
commit bafa7d4b24
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 9 additions and 3 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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.