From 54301121f8360e0d736c3e16a83eb9c6037a19e3 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 11 Oct 2022 11:07:12 -0600 Subject: [PATCH] fix(fsevents): correctly handle unknown events 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 ps-id: 204d7599-9ffb-4e95-8cff-871f39b4dc68 --- src/fsevents/fsevents_stubs.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/fsevents/fsevents_stubs.c b/src/fsevents/fsevents_stubs.c index c1c657972133..6d7aee40ba0e 100644 --- a/src/fsevents/fsevents_stubs.c +++ b/src/fsevents/fsevents_stubs.c @@ -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