From 66b99ab7f56d9f420b7e59a38e542158b0efd2a1 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 14 Jun 2019 15:08:14 +0200 Subject: [PATCH] Poll directory changes before resolving start promise on Windows When watching a path on Windows, a new thread gets spawned and a function is scheduled to be executed onto such thread. This function's responsibility is to invoke `ReadDirectoryChangesW` for the first time and to wake up the thread which invoked `Watcher::start`, signaling that nsfw is ready to report events. Previously, the main thread would be woken up _before_ calling `ReadDirectoryChangesW`. If any event occurred before or as `ReadDirectoryChangesW` took place, it wouldn't be reported to clients because that API only reports changes that occur _between_ calls to it. This commit fixes the issue by waiting for `ReadDirectoryChangesW` to have been called before waking up the main thread. This ensures that file system events occurring after watching has started are always reported to clients. --- src/win32/Watcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win32/Watcher.cpp b/src/win32/Watcher.cpp index e7190dbe..8a504ea9 100644 --- a/src/win32/Watcher.cpp +++ b/src/win32/Watcher.cpp @@ -236,8 +236,8 @@ void Watcher::start() { QueueUserAPC([](__in ULONG_PTR self) { auto watcher = reinterpret_cast(self); - watcher->mHasStartedSemaphore.signal(); watcher->pollDirectoryChanges(); + watcher->mHasStartedSemaphore.signal(); } , mRunner.native_handle(), (ULONG_PTR)this); if (!mHasStartedSemaphore.waitFor(std::chrono::seconds(10))) {