feat: emit subtree creates on dir move-in; normalize FSEvents renames

This commit is contained in:
CJ van den Berg 2026-03-29 23:30:32 +02:00
parent bfd1125449
commit ea72e0654d
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
8 changed files with 122 additions and 12 deletions

View file

@ -7,8 +7,9 @@ const ObjectType = types.ObjectType;
pub const watches_recursively = true; // FSEventStreamCreate watches the entire subtree
pub const detects_file_modifications = true;
pub const emits_close_events = false;
pub const emits_rename_for_files = true;
pub const emits_rename_for_dirs = true;
pub const emits_rename_for_files = false;
pub const emits_rename_for_dirs = false;
pub const emits_subtree_created_on_movein = false; // FSEvents emits per-path events only; no subtree synthesis
handler: *Handler,
stream: ?*anyopaque, // FSEventStreamRef
@ -235,7 +236,11 @@ fn callback(
ctx.handler.change(path, .deleted, ot) catch {};
}
if (flags & kFSEventStreamEventFlagItemRenamed != 0) {
ctx.handler.change(path, .renamed, ot) catch {};
// FSEvents fires ItemRenamed for both sides of a rename unpaired.
// Normalize to created/deleted based on whether the path still exists,
// so move-in appears as created and move-out as deleted on all platforms.
const exists = if (std.fs.accessAbsolute(path, .{})) |_| true else |_| false;
ctx.handler.change(path, if (exists) .created else .deleted, ot) catch {};
}
if (flags & kFSEventStreamEventFlagItemModified != 0) {
ctx.handler.change(path, .modified, ot) catch {};