SpartanJ / efsw

efsw is a C++ cross-platform file system watcher and notifier.
Other
662 stars 101 forks source link

First renaming does not generate an event on Windows #111

Closed merwaaan closed 3 years ago

merwaaan commented 3 years ago

Hi, It seems that the Actions::Moved event is not triggered the very first time a watched file is renamed when we use the Win32 watcher.

Steps to reproduce the issue:

Please note that this does NOT happen with the generic watcher implementation: instead it triggers Add and Delete events but at least it does not miss the first one.

merwaaan commented 3 years ago

Additional investigation shows that this actually happens when the file is not a direct child of the watched folder.

edit: the Add event does not seem to work properly either.

SpartanJ commented 3 years ago

Hi! Thanks for reporting this! The issue isn't exactly what you describe but it's pretty close. The exact issue is: the first time that occurs a file change since listening for changes from the file system, for some reason the OS is only reporting the folder change and not any file change, but only for the first time, and only when the change happened from a sub-directory of the originally watched directory. I'm currently investigating if there's an actual easy fix or I have to change the way the library watch folders recusivelly.

SpartanJ commented 3 years ago

@merwaaan let me know if this fixes the issue for you.

merwaaan commented 3 years ago

Thanks for the quick reply @SpartanJ ! I ran a few tests and renaming in sub-directories now works consistently.

However moving files in and from from sub-directories still has the same issue (Either the Add or Delete event is missing).

merwaaan commented 3 years ago

Your latests commits have fixed the issue. Thanks! 😀

Another issue that I just noticed is that copying a directory that contains a few files to the watched directory only generates an Add event for the copied directory and none for the files that it contains. I'm not sure if this is a bug or the expected behavior though.

SpartanJ commented 3 years ago

Great to hear! I had to make some core changes, now should be much more precise. I'll keep this issue open for a couple of days while I continue testing them.

Regarding the other issue: that's the expected behavior, in that case, there are no added files, those files are already created, it's just a directory movement. In that case, you'll need to scan the new directory and add those files.