Hi, we now use a Nodejs lib named chokidar to monitor our local directory's change. But we found it locked the parent and parent of the parent directory and ... of monitored-dir, which led to the failure to rename or delete. We tried to trace this problem and found it's CreateFile's weird behavior. The example code is below:
int main() {
LPCWSTR path = ConvertToLPCWSTR("c:\\sync123456\\");
printf("watching %s for changes...\n", path);
HANDLE file = CreateFileW(path,
FILE_LIST_DIRECTORY,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
NULL);
Sleep(6000000);
}
We checked the parameters of CreateFileW according to the MS manual and Node's (libuv exactly) source code; they looked good. This problem can be reproduced easily in Win10 or Win11, and we believe it still exists in other versions.
I sincerely hope someone can tell me why it happened and how.
Thanks!