gmethvin / directory-watcher

A cross-platform Java recursive directory watcher, with a JNA macOS watcher and Scala better-files integration
Apache License 2.0
265 stars 34 forks source link

Walk the directory to notify creation events when a directory is created #11

Closed jkawamoto closed 6 years ago

jkawamoto commented 6 years ago

This PR fixes #10.

jkawamoto commented 6 years ago

Thank you for your comments. According to the above comments and https://github.com/gmethvin/directory-watcher/issues/10#issuecomment-372015307, I modified the code so that it uses pathHashes to prevent sending duplicate creation events.

gmethvin commented 6 years ago

@jkawamoto There is still a duplicate directory create event: https://ci.appveyor.com/project/gmethvin/directory-watcher/build/108#L1121.

That's because for CREATE events we don't check hashes and always call onEvent: https://github.com/gmethvin/directory-watcher/blob/v0.4.0/core/src/main/java/io/methvin/watcher/DirectoryWatcher.java#L152.

For it to work we need to always check that the hash doesn't exist before emitting the event, even for directories.

jkawamoto commented 6 years ago

I modified the code so that it checks if a creation event has been notified. So far, tests passed in Windows and macOS. For Linux, I need more investigation.

gmethvin commented 6 years ago

It looks like a flaky test. It looks like we are getting a CREATE then MODIFY for one.txt when we were expecting just a CREATE. That is probably fine though, since the FileSystem#create method is writing some data to the file when it creates the file, so from the filesystem's point of view the file is being "modified". Just a guess but it might help to change FileSystem#create(path) to write an empty file rather than writing the path.

jkawamoto commented 6 years ago

That's true. It should be same as one in notifyCreateEvent. I refactored them so that notifyCreateEvent can be used by both.

jkawamoto commented 6 years ago

Thank you for the comment. I modified it.

gmethvin commented 6 years ago

I released version 0.5.1 with this change.

jkawamoto commented 6 years ago

I appreciate it.