Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watcher does not detect (re)moving a parent directory #77

Open
PhilGal opened this issue May 11, 2021 · 4 comments
Open

Watcher does not detect (re)moving a parent directory #77

PhilGal opened this issue May 11, 2021 · 4 comments

Comments

@PhilGal
Copy link

PhilGal commented May 11, 2021

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.

@PhilGal PhilGal changed the title Watcher does not detect deletion of a parent directory Watcher does not detect (re)moving a parent directory May 11, 2021
@gmethvin
Copy link
Owner

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.

@PhilGal
Copy link
Author

PhilGal commented May 14, 2021

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.

@eskatos
Copy link

eskatos commented Sep 16, 2024

How does the watcher behave when the deleted/moved directories are put back in place?

@gmethvin
Copy link
Owner

That likely also depends on the OS implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants