Skip to content

Commit

Permalink
fix(dirmonitor): avoid calling the change callback multiple times in …
Browse files Browse the repository at this point in the history
…the same notification
  • Loading branch information
Guldoman committed Jun 22, 2024
1 parent 290c7bc commit 50ffde3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/api/dirmonitor/inotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ int get_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, in


int translate_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, int length, int (*change_callback)(int, const char*, void*), void* data) {
for (struct inotify_event* info = (struct inotify_event*)buffer; (char*)info < buffer + length; info = (struct inotify_event*)((char*)info + sizeof(struct inotify_event)))
change_callback(info->wd, NULL, data);
// Only call the callback once, reducing all the events to a single one,
// as we aren't sending back any info about them anyways.
struct inotify_event* info = (struct inotify_event*)buffer;
change_callback(info->wd, NULL, data);
return 0;
}

Expand Down
6 changes: 4 additions & 2 deletions src/api/dirmonitor/kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ int get_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, in


int translate_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, int buffer_size, int (*change_callback)(int, const char*, void*), void* data) {
for (struct kevent* info = (struct kevent*)buffer; (char*)info < buffer + buffer_size; info = (struct kevent*)(((char*)info) + sizeof(kevent)))
change_callback(info->ident, NULL, data);
// Only call the callback once, reducing all the events to a single one,
// as we aren't sending back any info about them anyways.
struct kevent* info = (struct kevent*)buffer;
change_callback(info->ident, NULL, data);
return 0;
}

Expand Down

0 comments on commit 50ffde3

Please sign in to comment.