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

Feature request: Allow user-defined filtering before setting a watch #291

Open
queer opened this issue Mar 19, 2021 · 10 comments
Open

Feature request: Allow user-defined filtering before setting a watch #291

queer opened this issue Mar 19, 2021 · 10 comments
Labels
A-enhancement Z-needs implementation Needs an implementation, will accept PRs

Comments

@queer
Copy link

queer commented Mar 19, 2021

#255 is related but is NOT the same thing.

I have a use-case in which I want to watch my entire $HOME. However, due to WINE prefixes and other circumstances, it turns out I have a bunch of symlinks into / by accident. This is causing the inotify watcher to recurse through the entire directory tree and error out when it can't set a watch on something owned by root and not world-readable. It'd be nice to be able to filter out symlinks that specifically go to /.

Beyond this, it would be nice to be able to make something equivalent to ignore to ex. not open watches on a node_modules folder or other ignored files.

If this is worth adding, I'll try to put together a PR for this.

@0xpr03
Copy link
Member

0xpr03 commented Mar 20, 2021

Hi, I like the idea of using the ignore crate, though maybe it's also worth to add some option of disabling symlinks? Would need some investigation how easy that could be implemented. At best we can find a solution that does not take much overhead and makes sense across systems (as symlinks on windows are kinda irrelevant ?).

@0xpr03 0xpr03 added A-enhancement Z-needs implementation Needs an implementation, will accept PRs labels Mar 20, 2021
@0xpr03
Copy link
Member

0xpr03 commented Mar 20, 2021

Regarding ignore: I'm not sure if we want to introduce this as a direct dependency but I'm also on the fence how we could implement this in the most user friendly way without adding another callback to allow setting your own filter implementation.

One reason is that I'd only introduce this ignore api as an feature, though it's probably something many people might want. On the other side I personally dislike adding more callbacks as we really don't want to block in the core watcher implementation.

@queer
Copy link
Author

queer commented Mar 20, 2021

Thanks for the response!

[...]though maybe it's also worth to add some option of disabling symlinks?

The specific use-case I'm having can't just blanket-ignore symlinks, unfortunately. Some of the directories in my $HOME that I'd want to watch are symlinks to other drives (think ex. games being installed on an SSD while $HOME is an HDD), hence why I'd prefer more-specific filtering ("don't follow a symlink to /, but follow it to these other directories").

Regarding ignore[...]

A large part of why I'm interested in using ignore is because it allows a parallel walk of the target directory, and I'm using it in other parts of my code already. It looks like you can disable the standard filters which I imagine should be enough for not causing compatibility issues? Would need testing for sure. ignore also allows custom filtering of directories -- which could be used for preventing my specific use-case -- and blanket-disabling of symlink following which would also fix #255.

I understand not really wanting to add another dependency / callback / etc. for this, and that's fine with me ^^ I'm mostly just trying to avoid reimplementing notify on top of ignore myself, tho I don't mind doing so if it comes to it.

In the short term, I can likely handle this via traversing the directory tree with ignore and setting non-recursive watches myself.

@0xpr03
Copy link
Member

0xpr03 commented Mar 20, 2021

The specific use-case I'm having can't just blanket-ignore symlinks, unfortunately. Some of the directories in my $HOME that I'd want to watch are symlinks to other drives (think ex. games being installed on an SSD while $HOME is an HDD), hence why I'd prefer more-specific filtering ("don't follow a symlink to /, but follow it to these other directories").

This would be possible by simply filtering what to watch instead of filtering which symlinks to follow, wouldn't it ? So we don't need another filtering API besides the ignore filter.

@queer
Copy link
Author

queer commented Mar 20, 2021

Yes! Filtering what to watch would solve the entirety of my current issues.

@0xpr03
Copy link
Member

0xpr03 commented Mar 20, 2021

Ok if you want you can add this as a PR against main so it'll be added to an upcoming v5-pre release.

@0xpr03
Copy link
Member

0xpr03 commented Mar 20, 2021

Otherwise I'll probably have to wait after #288 and #286 on my side to make myself a mental model of how I'd add this API and add it for every OS (which is the real meat of that PR).

@0xpr03
Copy link
Member

0xpr03 commented Mar 20, 2021

Also I'd probably want to add a "don't follow symlinks at all" option, which could come in handy.

@0xpr03
Copy link
Member

0xpr03 commented Mar 20, 2021

Oh an if you want to do this PR by yourself you could feature-gate a ignore dependency or add an example how you can utilize this with the new API. (possibly using a callback and stuffing ignore inside?)

@queer
Copy link
Author

queer commented Apr 20, 2021

Hmm, after rethinking my wants, I think I really just need a "don't follow symlinks" in the end. I also couldn't come up with a good API that actually ended up working here :< I'll leave this open in case there's interest in implementing this in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-enhancement Z-needs implementation Needs an implementation, will accept PRs
Projects
None yet
Development

No branches or pull requests

2 participants