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

Watch non-existing directory recursivly by PollSystem #477

Open
Shelim opened this issue Apr 23, 2023 · 2 comments
Open

Watch non-existing directory recursivly by PollSystem #477

Shelim opened this issue Apr 23, 2023 · 2 comments

Comments

@Shelim
Copy link

Shelim commented Apr 23, 2023

(Yes, I know it looks like copy of #459 but it is actually a bit different problem):

  • I set-up notify for given directory (recursively) using PollSystem (every 1 second)
  • Now, if I remove directory completely, PollSystem will correctly report that all files inside (and the directory itself) were removed
  • If I re-create directory during the same session, PollSystem will correctly report that new files/directories were added

But! If I run exactly the same PollSystem for non-existing directory, it will return error and not install a watch whatsoever (even if the directory is set to be created one second later).

This is inconsistent behavior in my opinion - removing and re-creating directory for existing notifier is completely OK operation but watching non-existing and then re-created directory fails at initialization

@0xpr03
Copy link
Member

0xpr03 commented Apr 23, 2023

The problem here is that pollwatcher just accidentally reports this, as it just checks periodically for paths. You could say this is undefined behaviour in the wild.

Let's see what is happening globally: For inotify we tell the kernel to report us changes per inode, for windows we get changes recursively for a whole folder.

If you would try to do the same here, you would get an error, as inotify can't report anything for non existing inodes, and windows won't work the same. You would have to watch the parent folder. Now one could change this to watch the parent folder of a path, if it doesn't exist. But that is kind of a chicken / egg problem: When do we error out ? After recursing to / and still failing to watch it ? And we would have to conceal that we're actually getting events for much more than the intended path. Which for linux isn't free, as we'll eventually reach the inotify limits based on watched inodes.

If we would change pollwatcher to allow watching a non existent path, it would be inconsistent with the other backends. And thus any code using the recommended backend may fail the moment the OS leads to a change from the pollwatcher to any other backend by chance.

@Shelim
Copy link
Author

Shelim commented Apr 29, 2023

Ah, I see. In such case I think I need only pollwatcher capabilities, not the entire notify. Thanks for explaining that :)

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

2 participants