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
cannot watch non-existent files #49
Comments
It depends a lot on which OS you're using, but you probably want to watch the directory that you will be creating a file in. |
-1 No I'm not, because the folder doesn't exist as well. |
@freaker2k7 Then keep going up the directory tree until something exists. |
That misses the whole point. The whole beauty is to be able to watch the folder once it's created and on. |
Ok. I'm just telling you what will work. |
What I've done in a few situations is to watch a directory and whenever it changes, I walk the whole tree and add any missing directories to my watch list. Easy peasy. |
That's an awful solution when you have a big folder like /etc, /dev or any other directory with many files. |
Well, that's how inotify works. Whether you do this from your application or if this functionality is added to fsnotify, it's going to "abuse the IO" just the same. |
Pretty much all file notification backends work by getting a file descriptor or handle to the path you want to watch; if this path doesn't exist, then we can't get a file descriptor. The general strategy for this will be to wait until the path exists:
I'm not convinced that this is something that needs to be added to this library; it's quite a bit of plumbing to do this well which makes this more complex, and this is the only issue raised about this that I can find in ten years, so there doesn't seem to be that much demand for it. Should probably document though. |
Maybe I'm mis-understanding the semantics of fsnotify, but I'm surprised by the fact that I can't watch non-existent files. E.g., I can't watch a filename and then get a CREATE event when it's created. Or, if I watch a file and it's replaced via a REMOVE then I can no longer track it. This means that to reliably track changes to a file I must watch the file's directory!?
Example:
Test:
The text was updated successfully, but these errors were encountered: