Watcher does not detect (re)moving a parent directory
Opened this issue · 4 comments
In our project we subscribe for multiple tracked folders, and when any of them is (re)moved, the watcher closes itself, and that can be tracked in a completable future.
Example watched paths:
/Users/user/parentDir/watchedDir1
/Users/user/parentDir/watchedDir2
However, when we move the parentDir
out of the scope (or simply delete it), the watcher stays silent and keeps watching the basically invalid paths. When the tree is recreated, the changes are detected automatically.
This behaviour looks a bit weird as I'd expect at least some callback from the watcher. Why would it watch the invalid path?
Thank you.
That's interesting. It's possible the Java WatchService is not firing any events in that case, because the event occurred on the parent and not on the watched directories.
Which operating systems have you tried on?
I definitely think we need more clear and consistent behavior when roots and parents of roots get deleted.
I've tested it on Windows and macos, and there's a bit different behaviour.
Initial condition: start watcher on some parentDir/watchedDir
Delete watchedDir
- Mac: deletion is detected and the watcher exists
- Win: deletion is not detected, watcher runs
Delete parentDir/watchedDir
- Mac: deletion is not detected, watcher runs
- Win: deletion is not detected, watcher runs
So, looks like macos's native library detects when the path is gone, and win's doesn't.
I don't know the implementation details in depths but probably a simple periodical check that the watching path is still resolved should be sufficient.
How does the watcher behave when the deleted/moved directories are put back in place?
That likely also depends on the OS implementation