guard / listen

The Listen gem listens to file modifications and notifies you about the changes.
https://rubygems.org/gems/listen
MIT License
1.91k stars 245 forks source link

Disable recursion under Linux #556

Open sebbASF opened 2 years ago

sebbASF commented 2 years ago

Does not seem possible to disable recursion under Linux. It should be possible to watch a single directory, without any subdirectories.

ColinDKelley commented 1 year ago

@sebbASF I don't think this is a feature of the underlying drivers like fs-event, is it?

It's not too hard to skip over the changes you don't want in the callbacks, is it?

sebbASF commented 1 year ago

It may not be hard, but why not allow this to be optionally done by the library?

ColinDKelley commented 1 year ago

but why not allow this to be optionally done by the library?

I was thinking to keep this gem uncomplicated. But if you want to propose an interface that allows that, please throw a proposal together.

Also, just to confirm, it sounds like you agree that this isn't a feature of the underlying drivers like fs-event?

sebbASF commented 1 year ago

AIUI under Linux, the gem uses inotify via rb-inotify. Now inotify does not support recursion directly, so rb-inotify emulates this if the :recursive flag is provided. By default it looks like listen includes the :recursive flag when configuring rb-inotify.

The problem is that it does not appear to be possible to disable this setting.

sebbASF commented 1 year ago

This is important because each additional directory monitored by inotify takes up system resources. So although events can be filtered out later, for large directory trees there can be significant overhead.

ColinDKelley commented 1 year ago

Now inotify does not support recursion directly, so rb-inotify emulates this if the :recursive flag is provided. By default it looks like listen includes the :recursive flag when configuring rb-inotify.

Ok, that sounds like a good reason to allow recursion to be disabled. If we support that, we'll need to disable it on the other drivers too. How difficult does that seem?