Closed chromy96 closed 6 years ago
Calculating the hash of files is not strictly required, but it is useful to prevent unnecessary duplicate events from being emitted. Perhaps we can provide an option to disable this feature for regular files? Hashing also effects performance somewhat so some people may want to disable hashing for other reasons.
Option for disabling hashing files woud be a great addition. I can provide the first implementation if you're busy right now.
A pull request would be great, or else I'll probably look at implementing it sometime the next month or so.
Fixed by #14
DirectoryWatcher is trying to calculate the hash of every created/modified file when the event is emitted. Because of it, if the file is locked by the process writting to it, it can happen that some create/modify events are not emitted.
The error happens in PathUtils.hash(Path file) method. If you enable logging in catch clause, you will see that sometimes hash calculation fails with the following exception:
My question is: Is it necessary to calculate the hash of the files at all? Would it be enough to keep only directories in hash map and emit all the events for the files as they happen?
Here's the gist with the test case that reproduces the issue for create event: https://gist.github.com/chromy96/def29f4e9a0430e90f9ae28434fcc0f7