How do I watch directories only? (i.e. I want to coalesce multiple file update notifications in the same dir)
debajit opened this issue · 3 comments
I have code like the following to watch two directories. I only care about getting a notification when the directory is updated. For my use-case, I don't care about receiving notifications for #individual files getting changed.
{:ok, watcher_pid} = FileSystem.start_link(dirs: [dir1, dir2], latency: 2, file_events: false)
FileSystem.subscribe(watcher_pid)
With this code, when I create multiple files inside one of my watched directories e.g. by running mix new test
inside one watched directory, after 2s (the latency set above) I get lots of notifications in my handle_info
(I'm using a GenServer, as specified in your Readme) for all the files that just got created. (Similarly when I do a rm -rf watched_dir/another_dir
— I get lots of notifications too)
I would like to only get one notification that the directory has been updated. How do I do this with file_system
?
Hi @debajit
I think you have to do the filter yourself for now.
First, different backends have different behavior for different system, I guess you're using macos, but for Linux, it seems inotify
backend doesn't have the latency
config.
And then, I think it's very easy to do this with another gen_server process.
What Can I do:
- I forgot the reason I think recursive is enabled for macos and no option to disable it, will do a research and try to add it back.
- I'll test
latency
option, I'm not sure we get only one message totally or each message for each file change durning the latency time.
Thanks
And then, I think it's very easy to do this with another gen_server process.
Can you describe briefly how I could go about doing this?
I have the same request. However, I want to do that with the FSPoll backend.
BTW, I found by reading the code that the FSPoll backend doesn't send the change event for directories.