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

How do I watch directories only? (i.e. I want to coalesce multiple file update notifications in the same dir) #51

Open
debajit opened this issue May 27, 2018 · 3 comments

Comments

@debajit
Copy link

debajit commented May 27, 2018

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?

@falood
Copy link
Owner

falood commented May 30, 2018

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:

  1. 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.
  2. 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

@debajit
Copy link
Author

debajit commented Feb 22, 2019

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?

@zhangzhen
Copy link

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.

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

3 participants