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

File creation on Windows is sometimes not detected for copied files #56

Closed tvasenin closed 3 years ago

tvasenin commented 3 years ago

When I copy-paste a file into target dir on Windows, CREATE event is not reported.

This happens because at the moment of hashing the file it still in use (I don't know exactly why), and Files.exists() returns false as per specification (Files.notExists() would also return false in this case).

Proposal: if we get ENTRY_CREATE event for a file, but can't hash it, still report the CREATE event without updating pathHashes. An additional Files.notExists() check could also be employed to distinguish between "file has already been deleted" and "file exists but couldn't be accessed" situations.

gmethvin commented 3 years ago

Thanks @tvasenin for finding and reporting this issue.

Proposal: if we get ENTRY_CREATE event for a file, but can't hash it, still report the CREATE event without updating pathHashes. An additional Files.notExists() check could also be employed to distinguish between "file has already been deleted" and "file exists but couldn't be accessed" situations.

Seems like a reasonable approach. Also the additional check only needs to be performed if hashing is enabled.

Do you mind submitting a PR?

tvasenin commented 3 years ago

@gmethvin submitted PR #57.

gmethvin commented 3 years ago

Released the fix in 0.10.1