Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix: [deps/uv] fsevents: fix file event reporting (backport: v12.x) #100

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions deps/uv/src/unix/fsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,9 @@ void uv__fsevents_loop_delete(uv_loop_t* loop) {
#include <CoreFoundation/CFRunLoop.h>
#include <CoreServices/CoreServices.h>

/* These are macros to avoid "initializer element is not constant" errors
/* Macro to avoid "initializer element is not constant" errors
* with old versions of gcc.
*/
#define kFSEventsModified (kFSEventStreamEventFlagItemFinderInfoMod | \
kFSEventStreamEventFlagItemModified | \
kFSEventStreamEventFlagItemInodeMetaMod | \
kFSEventStreamEventFlagItemChangeOwner | \
kFSEventStreamEventFlagItemXattrMod)

#define kFSEventsRenamed (kFSEventStreamEventFlagItemCreated | \
kFSEventStreamEventFlagItemRemoved | \
kFSEventStreamEventFlagItemRenamed)

#define kFSEventsSystem (kFSEventStreamEventFlagUserDropped | \
kFSEventStreamEventFlagKernelDropped | \
kFSEventStreamEventFlagEventIdsWrapped | \
Expand Down Expand Up @@ -288,8 +278,6 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef,
path--;
len++;
}
/* Created and Removed seem to be always set, but don't make sense */
flags &= ~kFSEventsRenamed;
} else {
/* Skip forward slash */
path++;
Expand All @@ -310,12 +298,12 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef,

memset(event, 0, sizeof(*event));
memcpy(event->path, path, len + 1);
event->events = UV_RENAME;
event->events = UV_CHANGE;

if (0 == (flags & kFSEventsRenamed)) {
if (0 != (flags & kFSEventsModified) ||
0 == (flags & kFSEventStreamEventFlagItemIsDir))
event->events = UV_CHANGE;
if ((flags & kFSEventStreamEventFlagItemIsDir) ||
(flags & kFSEventStreamEventFlagItemRemoved) ||
(flags & kFSEventStreamEventFlagItemRenamed)) {
event->events = UV_RENAME;
}

QUEUE_INSERT_TAIL(&head, &event->member);
Expand Down
90 changes: 75 additions & 15 deletions deps/uv/test/test-fs-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ static char fs_event_filename[1024];
static int timer_cb_touch_called;
static int timer_cb_exact_called;

static void expect_filename(const char* path, const char* expected) {
#if defined(__APPLE__) || defined(_WIN32) || defined(__linux__)
ASSERT(0 == strcmp(path, expected));
#else
if (path != NULL)
ASSERT(0 == strcmp(path, expected));
#endif
}

static void fs_event_fail(uv_fs_event_t* handle,
const char* filename,
int events,
Expand Down Expand Up @@ -130,11 +139,7 @@ static void fs_event_cb_dir(uv_fs_event_t* handle, const char* filename,
ASSERT(handle == &fs_event);
ASSERT(status == 0);
ASSERT(events == UV_CHANGE);
#if defined(__APPLE__) || defined(_WIN32) || defined(__linux__)
ASSERT(strcmp(filename, "file1") == 0);
#else
ASSERT(filename == NULL || strcmp(filename, "file1") == 0);
#endif
expect_filename(filename, "file1");
ASSERT(0 == uv_fs_event_stop(handle));
uv_close((uv_handle_t*)handle, close_cb);
}
Expand Down Expand Up @@ -312,11 +317,7 @@ static void fs_event_cb_file(uv_fs_event_t* handle, const char* filename,
ASSERT(handle == &fs_event);
ASSERT(status == 0);
ASSERT(events == UV_CHANGE);
#if defined(__APPLE__) || defined(_WIN32) || defined(__linux__)
ASSERT(strcmp(filename, "file2") == 0);
#else
ASSERT(filename == NULL || strcmp(filename, "file2") == 0);
#endif
expect_filename(filename, "file2");
ASSERT(0 == uv_fs_event_stop(handle));
uv_close((uv_handle_t*)handle, close_cb);
}
Expand All @@ -339,11 +340,7 @@ static void fs_event_cb_file_current_dir(uv_fs_event_t* handle,
ASSERT(handle == &fs_event);
ASSERT(status == 0);
ASSERT(events == UV_CHANGE);
#if defined(__APPLE__) || defined(_WIN32) || defined(__linux__)
ASSERT(strcmp(filename, "watch_file") == 0);
#else
ASSERT(filename == NULL || strcmp(filename, "watch_file") == 0);
#endif
expect_filename(filename, "watch_file");

/* Regression test for SunOS: touch should generate just one event. */
{
Expand Down Expand Up @@ -619,6 +616,69 @@ TEST_IMPL(fs_event_watch_file_exact_path) {
return 0;
}

static void file_remove_cb(uv_fs_event_t* handle,
const char* path,
int events,
int status) {
fs_event_cb_called++;

expect_filename(path, "file1");
/* TODO(bnoordhuis) Harmonize the behavior across platforms. Right now
* this test merely ensures the status quo doesn't regress.
*/
#if defined(_AIX) || defined(__linux__)
ASSERT(UV_CHANGE == events);
#else
ASSERT(UV_RENAME == events);
#endif
ASSERT(0 == status);

uv_close((uv_handle_t*) handle, NULL);
}

static void file_remove_next(uv_timer_t* handle) {
uv_close((uv_handle_t*) handle, NULL);
remove("watch_dir/file1");
}

static void file_remove_start(uv_timer_t* handle) {
uv_fs_event_t* watcher;
uv_loop_t* loop;

loop = handle->loop;
watcher = handle->data;

ASSERT(0 == uv_fs_event_init(loop, watcher));
ASSERT(0 == uv_fs_event_start(watcher, file_remove_cb, "watch_dir/file1", 0));
ASSERT(0 == uv_timer_start(handle, file_remove_next, 50, 0));
}

TEST_IMPL(fs_event_watch_file_remove) {
uv_fs_event_t watcher;
uv_timer_t timer;
uv_loop_t* loop;

#if defined(__MVS__)
RETURN_SKIP("test does not work on this OS");
#endif

remove("watch_dir/file1");
remove("watch_dir/");
create_dir("watch_dir");
create_file("watch_dir/file1");

loop = uv_default_loop();
timer.data = &watcher;

ASSERT(0 == uv_timer_init(loop, &timer));
ASSERT(0 == uv_timer_start(&timer, file_remove_start, 500, 0));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
ASSERT(1 == fs_event_cb_called);

MAKE_VALGRIND_HAPPY();
return 0;
}

TEST_IMPL(fs_event_watch_file_twice) {
#if defined(NO_FS_EVENTS)
RETURN_SKIP(NO_FS_EVENTS);
Expand Down
2 changes: 2 additions & 0 deletions deps/uv/test/test-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ TEST_DECLARE (fs_event_watch_dir_short_path)
#endif
TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_exact_path)
TEST_DECLARE (fs_event_watch_file_remove)
TEST_DECLARE (fs_event_watch_file_twice)
TEST_DECLARE (fs_event_watch_file_current_dir)
#ifdef _WIN32
Expand Down Expand Up @@ -903,6 +904,7 @@ TASK_LIST_START
#endif
TEST_ENTRY (fs_event_watch_file)
TEST_ENTRY (fs_event_watch_file_exact_path)
TEST_ENTRY (fs_event_watch_file_remove)
TEST_ENTRY (fs_event_watch_file_twice)
TEST_ENTRY (fs_event_watch_file_current_dir)
#ifdef _WIN32
Expand Down