directory-watcher: Unable to detect file deletion events
Hello Greg and community,
This is maybe more of an informal request rather than a real issue. But maybe you are able to provide some info on this nonetheless.
I am currently trying to integrate your directory watcher 0.10.0 into one of our software components. Integration was quite easy but while running our test suite, I’ve noticed that file deletion events somehow do not get propagated to our application, while at the same time, file creation events and file modification events work without issues. We cannot really explain this behaviour to ourselves.
We run your directory watcher in a separate thread and start it using the .watch() method.
I’ve built a minimal, single-threaded POC watching a directory. And there, everything seemed to be working normal (all events received, even the deletion events).
I am not sure what could cause those deletion events to not being generated. Do you have any idea? We’re running on Java 13 and macOS Catalina 10.15.6 and macOS 11 Big Sur beta.
Any feedback highly appreciated.
Thanks! André
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 27 (15 by maintainers)
Commits related to this issue
- add test for issue #55 — committed to gmethvin/directory-watcher by gmethvin 2 years ago
- fixes #5 - :delete events are transmitted Details in: https://github.com/gmethvin/directory-watcher/issues/55 — committed to simongray/beholder by simongray 2 years ago
@simongray I released
0.17.1with the relative paths fix so you can try that and see if that fixes the issue for you.I think I discovered the issue.
This happens when two conditions are true:
Basically the issue is that the watcher initialization code uses the paths as hash keys as given—even if they are relative—but it is comparing against the absolute paths returned by the underlying watch service. The solution is to convert the paths to absolute before initializing the hash map.
@simongray thanks, it was helpful that you mentioned you do not receive delete events for files created before starting the watcher. It seems like our existing test cases for file deletion only considered files created after the watcher was started. I created a pull request with some additional tests: https://github.com/gmethvin/directory-watcher/pull/84.
In that PR I’m seeing the
deleteAlreadyExistingFiles*tests failing across all platforms, which suggests the issue is not specific to macOS or Apple Silicon.I haven’t had a chance to investigate the cause yet, but now we have a failing test it should be easier to understand what’s going on.