haskell-fswatch / hfsnotify

Unified Haskell interface for basic file system notifications
BSD 3-Clause "New" or "Revised" License
136 stars 40 forks source link

No modification notifications for symlinks #87

Open francisdb opened 5 years ago

francisdb commented 5 years ago

this has been copied over from https://github.com/haskell-fswatch/hfsnotify/issues/66#issuecomment-238694654 by @Prillan

Setup

/tmp$ tree fsnotify-test
fsnotify-test
├── files
│   └── test
└── links
    └── test -> ../files/test

Start the watcher in /tmp/fsnotify-test/links: watchTree mgr "/tmp/fsnotify-test/links/" (const True) print

The following commands illustrate this point

$ cd fsnotify-test/
$ touch files/test
<no output from watcher>
$ echo "ASDF" >> files/test
<no output from watcher>
$ echo "ASDF" >> links/test
<no output from watcher>
$ ln -s files/test links/test2
Added "/tmp/fsnotify-test/links/test2" 2016-08-09 21:09:36.370309 UTC
$ rm files/test
<no output from watcher>
$ rm links/test
Removed "/tmp/fsnotify-test/links/test" 2016-08-09 21:10:05.512831 UTC

Note that the only actions output were the ones affecting the links themselves.

thomasjm commented 5 years ago

I believe this is the expected/desired behavior. A symlink is just a special kind of file which contains a path to another file (which may not even exist). As the man page says, "Inotify monitoring is inode-based," so we wouldn't expect a change to the target of a symlink to be picked up.

I think you'll have to watch the whole tree to catch such modifications.

francisdb commented 5 years ago

This indeed seems to be a complicated subject. Differences between operating systems and chance of infinite recursion.

eg https://github.com/guard/listen/issues/25

thomasjm commented 5 years ago

Yes it is tricky. Hopefully you can solve your problem by adding watches to wherever the files actually live, since inotify doesn't provide a way to watch for this. I don't think fanotify, the other Linux file watching system, does either. Not sure about Windows or Mac but I suspect it's the same situation.

Going to close this but let me know if you have any other thoughts.

thomasjm commented 5 years ago

Well actually -- the fswatch library is kind of a gold standard and it looks like they have done some work on this. See https://github.com/emcrisostomo/fswatch/issues/87, they mention that for inotify they added the ability to scan the filesystem and add more watches when the --follow-links argument is given.

So I guess we could consider this a feature request to add similar functionality. You'd still be out of luck on OSX though.

karlicoss commented 4 years ago

If someone's looking for workaround, https://github.com/jaspervdj/hakyll/issues/502#issuecomment-557895182 might help you