Skip to content

Commit badecdc

Browse files
authored
fsevents: detect watched directory removal (#4376)
Which was broken both in `windows` and `macos`.
1 parent 8330658 commit badecdc

4 files changed

Lines changed: 152 additions & 60 deletions

File tree

src/unix/fsevents.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,6 @@ static void uv__fsevents_event_cb(const FSEventStreamRef streamRef,
276276
path += handle->realpath_len;
277277
len -= handle->realpath_len;
278278

279-
/* Ignore events with path equal to directory itself */
280-
if (len <= 1 && (flags & kFSEventStreamEventFlagItemIsDir))
281-
continue;
282-
283279
if (len == 0) {
284280
/* Since we're using fsevents to watch the file itself,
285281
* realpath == path, and we now need to get the basename of the file back

src/win/fs-event.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,25 @@ void uv__process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
561561
}
562562
} else {
563563
err = GET_REQ_ERROR(req);
564-
handle->cb(handle, NULL, 0, uv_translate_sys_error(err));
564+
/*
565+
* Check whether the ERROR_ACCESS_DENIED is caused by the watched directory
566+
* being actually deleted (not an actual error) or a legit error. Retrieve
567+
* FileStandardInfo to check whether the directory is pending deletion.
568+
*/
569+
FILE_STANDARD_INFO info;
570+
if (err == ERROR_ACCESS_DENIED &&
571+
handle->dirw != NULL &&
572+
GetFileInformationByHandleEx(handle->dir_handle,
573+
FileStandardInfo,
574+
&info,
575+
sizeof(info)) &&
576+
info.Directory &&
577+
info.DeletePending) {
578+
uv__convert_utf16_to_utf8(handle->dirw, -1, &filename);
579+
handle->cb(handle, filename, UV_RENAME, 0);
580+
} else {
581+
handle->cb(handle, NULL, 0, uv_translate_sys_error(err));
582+
}
565583
}
566584

567585
if (handle->flags & UV_HANDLE_CLOSING) {

0 commit comments

Comments
 (0)