by contingencies · 9y ago · 0 comments
https://linux.die.net/man/7/inotify
https://en.wikipedia.org/wiki/Inotify
There is also a less well utilized fsnotify feature for filesystem-wide notifications. Here is a cross-platform go implementation which also supports OSX: https://github.com/fsnotify/fsnotify
Entr on the other hand works like a charm. You can see on the website that it details a number of edge cases with inotify that it works around. I'm not even sure it's an exhaustive list.
Also, inotify is suboptimal for this use case. inotify has no recursion support, which means that the user must keep a watch on all files individually. There is also a limit to the number of inotify watches that can be in place at any one time.
A more modern, and more suitable interface for this use case is fanotify[0]. It doesn't provide all the functions that inotify does, but importantly it supports recursion, which alone would seem to make it a more obvious choice for this task.
Any more information on this? I'm curious to read why.
fanotify is not an alternative because it cannot monitor file deletion or renames and it requires root permission.
If it doesn't care what file is modified and just wants to run a command on any change, why would it need to do this?
Another use-case is a desktop search tool.
$ fswatch -0 -event ./main.lua | xargs -0 -n 1 -I {} lua ./main.lua