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

Implement recursive fs watch on Windows #1473

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions include/uv-win.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
HANDLE dir_handle; \
int req_pending; \
uv_fs_event_cb cb; \
unsigned int win_flags; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call it fs_flags, this code in on the Windows side anyway.

WCHAR* filew; \
WCHAR* short_filew; \
WCHAR* dirw; \
Expand Down
23 changes: 20 additions & 3 deletions src/win/fs-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void uv_fs_event_queue_readdirchanges(uv_loop_t* loop,
if (!ReadDirectoryChangesW(handle->dir_handle,
handle->buffer,
uv_directory_watcher_buffer_size,
FALSE,
(handle->win_flags & UV_FS_EVENT_RECURSIVE) ? TRUE: FALSE,
FILE_NOTIFY_CHANGE_FILE_NAME |
FILE_NOTIFY_CHANGE_DIR_NAME |
FILE_NOTIFY_CHANGE_ATTRIBUTES |
Expand All @@ -63,6 +63,21 @@ static void uv_fs_event_queue_readdirchanges(uv_loop_t* loop,
handle->req_pending = 1;
}

static int uv_relative_path(const WCHAR* filename, const WCHAR* dir,
WCHAR** relpath) {
int dirlen = wcslen(dir);
int filelen = wcslen(filename);
if (dir[dirlen - 1] == '\\') {
dirlen--;
}
*relpath = (WCHAR*)malloc((MAX_PATH + 1) * sizeof(WCHAR));
if (!*relpath) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
wcsncpy(*relpath, filename + dirlen + 1, filelen - dirlen - 1);
(*relpath)[filelen - dirlen - 1] = L'\0';
return 0;
}

static int uv_split_path(const WCHAR* filename, WCHAR** dir,
WCHAR** file) {
Expand Down Expand Up @@ -137,6 +152,8 @@ int uv_fs_event_start(uv_fs_event_t* handle,
return UV_EINVAL;

handle->cb = cb;
// Added win_flags for recursive watcher
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous comment.

handle->win_flags = flags;
handle->path = strdup(path);
if (!handle->path) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
Expand Down Expand Up @@ -237,7 +254,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
if (!ReadDirectoryChangesW(handle->dir_handle,
handle->buffer,
uv_directory_watcher_buffer_size,
FALSE,
(handle->win_flags & UV_FS_EVENT_RECURSIVE) ? TRUE: FALSE,
FILE_NOTIFY_CHANGE_FILE_NAME |
FILE_NOTIFY_CHANGE_DIR_NAME |
FILE_NOTIFY_CHANGE_ATTRIBUTES |
Expand Down Expand Up @@ -410,7 +427,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,

if (long_filenamew) {
/* Get the file name out of the long path. */
result = uv_split_path(long_filenamew, NULL, &filenamew);
result = uv_relative_path(long_filenamew, handle->dirw, &filenamew);
free(long_filenamew);

if (result == 0) {
Expand Down