From 0a121575ca9b7a0a7eed1a60486545cf83b490bc Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Tue, 17 Mar 2026 16:45:54 +0100 Subject: [PATCH] win: decrease GetFinalPathNameByHandleW calls --- src/win/fs-event.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/win/fs-event.c b/src/win/fs-event.c index 7ef279f66..f67a6df73 100644 --- a/src/win/fs-event.c +++ b/src/win/fs-event.c @@ -433,6 +433,7 @@ void uv__process_fs_event_req(uv_loop_t* loop, uv_req_t* req, WCHAR* filenamew = NULL; WCHAR* long_filenamew = NULL; DWORD offset = 0; + int dir_event_detected = 0; assert(req->type == UV_FS_EVENT_REQ); assert(handle->req_pending); @@ -459,6 +460,10 @@ void uv__process_fs_event_req(uv_loop_t* loop, uv_req_t* req, assert(!filenamew); assert(!long_filenamew); + if (file_info->FileNameLength == 0) { + dir_event_detected = 1; + } + /* * Fire the event only if we were asked to watch a directory, * or if the filename filter matches. @@ -587,6 +592,7 @@ void uv__process_fs_event_req(uv_loop_t* loop, uv_req_t* req, sizeof(info)) && info.Directory && info.DeletePending) { + dir_event_detected = 1; uv__convert_utf16_to_utf8(handle->dirw, -1, &filename); handle->cb(handle, filename, UV_RENAME, 0); uv__free(filename); @@ -600,22 +606,25 @@ void uv__process_fs_event_req(uv_loop_t* loop, uv_req_t* req, uv__want_endgame(loop, (uv_handle_t*)handle); } else if (uv__is_active(handle)) { /* - * Check if the handle has become a zombie pointing to $Extend\$Deleted. - * If so, report as deleted and don't re-queue. + * Check if the handle has become a zombie pointing to \$Extend\$Deleted\. + * Only perform the check if we detected an event on the directory, which + * may indicate deletion. */ - WCHAR path_buf[MAX_PATH]; - DWORD path_len = GetFinalPathNameByHandleW(handle->dir_handle, - path_buf, - ARRAY_SIZE(path_buf), - FILE_NAME_NORMALIZED); - - if (path_len > 0 && path_len < MAX_PATH) { - if (wcsstr(path_buf, L"\\$Extend\\$Deleted\\") != NULL) { - handle->cb(handle, NULL, 0, UV_ENOENT); - return; + if (dir_event_detected) { + WCHAR path_buf[MAX_PATH]; + DWORD path_len = GetFinalPathNameByHandleW(handle->dir_handle, + path_buf, + ARRAY_SIZE(path_buf), + FILE_NAME_NORMALIZED); + + if (path_len > 0 && path_len < MAX_PATH) { + if (wcsstr(path_buf, L"\\$Extend\\$Deleted\\") != NULL) { + handle->cb(handle, NULL, 0, UV_ENOENT); + return; + } } } - + uv__fs_event_queue_readdirchanges(loop, handle); } }