cginternals/cppfs

File system watcher

Closed this issue · 18 comments

Is there any work being done on this ? I'm in need of a simple filesystem watcher and could maybe contribute with at least linux + windows watchers.

Let's do it then :)

I've created a branch and starting implementing the linux backend:
https://github.com/cginternals/cppfs/tree/watcher

You could start implementing the Windows backend, if you like.
Please comment on the architecture and design.

Actually, I've already implemented the Windows parts, and have started on linux backend, I'll push to my own fork it you want to check it out.

Since inotify isn't recursive, I need to add watches on subfolders, and handle creation of subfolders aswell. Please do have a view at https://github.com/robiwano/cppfs for the general design pattern for file watchers.

branch is feature/filewatch

ok, I'll look into it and copy the recursive stuff for the linux backend. We should decide whether we want to have recursive as a flag or not. If you could prepare a pull request for the Windows backend following the interface in the watcher branch, that would be great. Let me know if you want changes to the structure/interfaces etc.

I'll check the API in the watcher branch :)

I like that the watcher stuff is separate from FileHandle. I'll modify my code accordingly.

Please let me know if you are preparing a pull request for this branch to implement the Windows backend.

I have a question regarding blocking watch(): My usecase will be a plugin whos lifetime is totally controlled from the outside. The watch() method will be called within a separate thread, thus, when the plugin is destroyed, the watch() method must unblock in order to terminate the thread in an orderly fashion. Thoughts ?

Maybe add a timeout option to watch ? So it can return after X milliseconds ?

Ok, I'm going with the timeout parameter to watch, turns out to be to cleanest approach. Will also update the cppfs-watch example to take a time parameter so it exits the application after the given time.

I think having a timeout parameter would be a good solution. Please make it optional, so by default it should block without timeout. Maybe this helps for the posix implementation:
https://stackoverflow.com/questions/2917881/how-to-implement-a-timeout-in-read-function-call

Yes, I found that same exact post :), seems to work fine for posix implementation, now I just need to get my VS IDE up and running (license expired 😏 )...

Btw, is it possible via cppassist cmd line tools to get multiple unnamed parameters into a vector of strings ? I'd like to be able to set multiple paths to monitor in cppfs-watch.

Pull request issued.

This has finally been merged. Thank you very much for your contribution!
Please let me know if there are any more issues with this, or if I accidentally broke something with my latest changes :)