gradle / native-platform

Java bindings for various native APIs
Apache License 2.0
117 stars 38 forks source link

Windows file watcher reports renames incorrectly #59

Open lptr opened 4 years ago

lptr commented 4 years ago

The Windows native watcher currently sends one event for the removal of the source path, and no event for the target path.

For some reason we get events like this when renaming source.txt to target.txt in a watched directory:

~~~~ Configuring...
~~~~ Watching C:\Users\vmadmin\AppData\Local\Temp\junit3569962616360979317\junit2117301140375774919\
~~~~ Starting thread
~~~~ Changed: 4 C:\Users\vmadmin\AppData\Local\Temp\junit3569962616360979317\junit2117301140375774919\source.txt
~~~~ Changed: 3 C:\Users\vmadmin\AppData\Local\Temp\junit3569962616360979317\junit2117301140375774919
~~~~ Ignoring C:\Users\vmadmin\AppData\Local\Temp\junit3569962616360979317\junit2117301140375774919 (root is not watched)
~~~~ Stopping thread

The event we get for source.txt (4 = FILE_ACTION_RENAMED_OLD_NAME) is correct, but we should be getting a number 5 event (FILE_ACTION_RENAMED_OLD_NAME) for target.txt according to the (docs)[https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-file_notify_information]. Instead we get a 3 (FILE_ACTION_MODIFIED) for the parent directory.

lptr commented 4 years ago

Note that this is only a problem when renaming the file, i.e. when it stays in the same directory. Moving the file generates the correct FILE_ACTION_REMOVED + FILE_ACTION_ADDED events (plus another FILE_ACTION_MODIFIED for the directory of the target for some reason).

lptr commented 4 years ago

I was suspecting that using File.renameTo() might do something weird, but running REN source.txt target.txt in PowerShell produces the same events.