diff --git a/include/uv.h b/include/uv.h index c2efa0a9..58e424b1 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1166,13 +1166,33 @@ struct uv_fs_event_s { */ UV_EXTERN void uv_loadavg(double avg[3]); + /* -* If filename is a directory then we will watch for all events in that -* directory. If filename is a file - we will only get events from that -* file. Subdirectories are not watched. -*/ + * Flags to be passed to uv_fs_event_init. + */ +enum uv_fs_event_flags { + /* + * By default, if the fs event watcher is given a directory name, we will + * watch for all events in that directory. This flags overrides this behavior + * and makes fs_event report only changes to the directory entry itself. This + * flag does not affect individual files watched. + * This flag is currently not implemented yet on any backend. + */ + UV_FS_EVENT_WATCH_ENTRY = 1, + + /* + * By default uv_fs_event will try to use a kernel interface such as inotify + * or kqueue to detect events. This may not work on remote filesystems such + * as NFS mounts. This flag makes fs_event fall back to calling stat() on a + * regular interval. + * This flag is currently not implemented yet on any backend. + */ + UV_FS_EVENT_STAT = 2 +}; + + UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, - const char* filename, uv_fs_event_cb cb); + const char* filename, uv_fs_event_cb cb, int flags); /* Utility */ diff --git a/src/unix/cygwin.c b/src/unix/cygwin.c index 2f0680a4..024e7d5b 100644 --- a/src/unix/cygwin.c +++ b/src/unix/cygwin.c @@ -69,7 +69,8 @@ uint64_t uv_get_total_memory(void) { int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, - uv_fs_event_cb cb) { + uv_fs_event_cb cb, + int flags) { uv__set_sys_error(loop, ENOSYS); return -1; } diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index c2cb7194..00180cd4 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -86,9 +86,13 @@ void uv__kqueue_hack(EV_P_ int fflags, ev_io *w) { int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, - uv_fs_event_cb cb) { + uv_fs_event_cb cb, + int flags) { int fd; + /* We don't support any flags yet. */ + assert(!flags); + if (cb == NULL) { uv__set_sys_error(loop, EINVAL); return -1; @@ -122,7 +126,8 @@ void uv__fs_event_destroy(uv_fs_event_t* handle) { int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, - uv_fs_event_cb cb) { + uv_fs_event_cb cb, + int flags) { uv__set_sys_error(loop, ENOSYS); return -1; } diff --git a/src/unix/linux.c b/src/unix/linux.c index e7ca1840..aa16f981 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -156,10 +156,14 @@ static void uv__inotify_read(EV_P_ ev_io* w, int revents) { int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, - uv_fs_event_cb cb) { + uv_fs_event_cb cb, + int flags) { int flags; int fd; + /* We don't support any flags yet. */ + assert(!flags); + /* * TODO share a single inotify fd across the event loop? * We'll run into fs.inotify.max_user_instances if we diff --git a/src/unix/sunos.c b/src/unix/sunos.c index 10314e46..f5312207 100644 --- a/src/unix/sunos.c +++ b/src/unix/sunos.c @@ -137,9 +137,13 @@ static void uv__fs_event_read(EV_P_ ev_io* w, int revents) { int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, - uv_fs_event_cb cb) { + uv_fs_event_cb cb, + int flags) { int portfd; + /* We don't support any flags yet. */ + assert(!flags); + if ((portfd = port_create()) == -1) { uv__set_sys_error(loop, errno); return -1; diff --git a/src/win/fs-event.c b/src/win/fs-event.c index 54e39fa0..b2f6583a 100644 --- a/src/win/fs-event.c +++ b/src/win/fs-event.c @@ -133,12 +133,15 @@ static int uv_split_path(const wchar_t* filename, wchar_t** dir, int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, - const char* filename, uv_fs_event_cb cb) { + const char* filename, uv_fs_event_cb cb, int flags) { int name_size; DWORD attr, last_error; wchar_t* dir = NULL, *dir_to_watch, *filenamew; wchar_t short_path[MAX_PATH]; + /* We don't support any flags yet. */ + assert(!flags); + uv_fs_event_init_handle(loop, handle, filename, cb); /* Convert name to UTF16. */ diff --git a/test/test-fs-event.c b/test/test-fs-event.c index fe700f4f..c1f23fe9 100644 --- a/test/test-fs-event.c +++ b/test/test-fs-event.c @@ -144,7 +144,7 @@ TEST_IMPL(fs_event_watch_dir) { uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL); create_dir(loop, "watch_dir"); - r = uv_fs_event_init(loop, &fs_event, "watch_dir", fs_event_cb_dir); + r = uv_fs_event_init(loop, &fs_event, "watch_dir", fs_event_cb_dir, 0); ASSERT(r != -1); r = uv_timer_init(loop, &timer); ASSERT(r != -1); @@ -178,7 +178,7 @@ TEST_IMPL(fs_event_watch_file) { create_file(loop, "watch_dir/file1"); create_file(loop, "watch_dir/file2"); - r = uv_fs_event_init(loop, &fs_event, "watch_dir/file2", fs_event_cb_file); + r = uv_fs_event_init(loop, &fs_event, "watch_dir/file2", fs_event_cb_file, 0); ASSERT(r != -1); r = uv_timer_init(loop, &timer); ASSERT(r != -1); @@ -212,7 +212,7 @@ TEST_IMPL(fs_event_watch_file_current_dir) { create_file(loop, "watch_file"); r = uv_fs_event_init(loop, &fs_event, "watch_file", - fs_event_cb_file_current_dir); + fs_event_cb_file_current_dir, 0); ASSERT(r != -1); r = uv_timer_init(loop, &timer); @@ -248,7 +248,11 @@ TEST_IMPL(fs_event_no_callback_on_close) { create_dir(loop, "watch_dir"); create_file(loop, "watch_dir/file1"); - r = uv_fs_event_init(loop, &fs_event, "watch_dir/file1", fs_event_cb_file); + r = uv_fs_event_init(loop, + &fs_event, + "watch_dir/file1", + fs_event_cb_file, + 0); ASSERT(r != -1); uv_close((uv_handle_t*)&fs_event, close_cb);