gmethvin / directory-watcher

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

Better handle CREATE for already-hashed files #90

Closed gmethvin closed 1 year ago

gmethvin commented 1 year ago

If the file has already been hashed, it's possible we missed a DELETE event, either because of an unexpected exception in the event loop, or due to an OVERFLOW. In this case, we may receive a CREATE event when the file appears to already exist.

Note that we rely on the suppression of CREATE when new directories are created: we need to traverse the existing directory to notify CREATE for any files that may have existed before we started listening, but some of those files might have been created just after we started listening, leading to duplicate events.

In both of the above situations, we still want to avoid sending a CREATE, because the listener already thinks the file exists. If the hash hasn't changed, the listener is already aware of the state of the file, so it should be safe to suppress the CREATE event. If the content has changed, then we should send a MODIFY to notify the listener that something changed.