Skip to content

Commit

Permalink
fix(fsevents): correctly handle unknown events
Browse files Browse the repository at this point in the history
We should apply our action mask before converting it into an OCaml
variant. Otherwise, we'll get events that we don't understand.

Signed-off-by: Rudi Grinberg <[email protected]>

ps-id: 204d7599-9ffb-4e95-8cff-871f39b4dc68
  • Loading branch information
rgrinberg committed Oct 11, 2022
1 parent a757ad8 commit 5430112
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/fsevents/fsevents_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,22 @@ static const FSEventStreamEventFlags action_mask =
kFSEventStreamEventFlagItemCreated | kFSEventStreamEventFlagItemRemoved |
kFSEventStreamEventFlagItemRenamed | kFSEventStreamEventFlagItemModified;

static int count_set_bits(uint32_t bits) {
// XXX slow
int count = 0;
while (bits) {
count += (bits & 1);
bits >>= 1;
}
return count;
}

CAMLprim value dune_fsevents_action(value v_flags) {
CAMLparam1(v_flags);
CAMLlocal1(v_action);

uint32_t flags = Int32_val(v_flags) & action_mask;
// XXX slow
int count = 0;
while (flags) {
count += (flags & 1);
flags >>= 1;
}

flags = Int32_val(v_flags);
if (count >= 2 || flags & kFSEventStreamEventFlagItemRenamed) {
if (flags & kFSEventStreamEventFlagItemRenamed || count_set_bits(flags)) {
// we don't bother tracking renamed acurately for now. macos makes it
// tricky by not telling is which path is created and which one is deleted.
// it is possible to reverse engineer this from the chain of inodes in the
Expand Down

0 comments on commit 5430112

Please sign in to comment.