notify
notify copied to clipboard
Recursive watches on Linux reports wrong directories if directories are renamed.
I don't know how complete the support for recursive watches on Linux, but here are the steps to reproduce the problem.
I am using Ubuntu 15.10 64-bit within VirtualBox.
I am also using the notify command line program from: https://github.com/rjeczalik/cmd/tree/master/notify
First, I set up the watcher like so:
$:~$ cd Desktop
$:~/Desktop$ mkdir notify-test
$:~/Desktop$ notify -c 'echo "Hello from handler! (event={{.Event}}, path={{.Path}})"'
Then, I make the following changes to the filesystem:
- Create folder
test
using the file manager (nautilus). - Within
test
create another folder calledtest-child
using the file manager. - Within
test-child
, createtest-grand-child
using the file manager.
This is the output from the notifier:
2016/03/10 18:58:58 received notify.Create: "/home/user/Desktop/notify-test/Untitled Folder"
Hello from handler! (event=create, path=/home/user/Desktop/notify-test/Untitled Folder)
2016/03/10 18:59:02 received notify.Rename: "/home/user/Desktop/notify-test/Untitled Folder"
2016/03/10 18:59:02 received notify.Rename: "/home/user/Desktop/notify-test/Untitled Folder"
2016/03/10 18:59:02 event dropped due to slow handler
2016/03/10 18:59:02 received notify.Create: "/home/user/Desktop/notify-test/test"
2016/03/10 18:59:02 event dropped due to slow handler
Hello from handler! (event=rename, path=/home/user/Desktop/notify-test/Untitled Folder)
2016/03/10 18:59:48 received notify.Create: "/home/user/Desktop/notify-test/Untitled Folder/Untitled Folder"
Hello from handler! (event=create, path=/home/user/Desktop/notify-test/Untitled Folder/Untitled Folder)
2016/03/10 18:59:51 received notify.Create: "/home/user/Desktop/notify-test/Untitled Folder/test-child"
2016/03/10 18:59:51 received notify.Rename: "/home/user/Desktop/notify-test/Untitled Folder/Untitled Folder"
2016/03/10 18:59:51 event dropped due to slow handler
Hello from handler! (event=create, path=/home/user/Desktop/notify-test/Untitled Folder/test-child)
There are 3 problems here:
- When a folder is first created, the file manager names it
Untitled Folder
. Even though we assign the folder's name to betest
, the notifier still returnsUntitled Folder
in the event's path when a descendent changes. - Notifier seems to not detect changes at the third level (
test-grand-child
) and produces no events. - I tried changing the event channel buffer to 100, but it still warns about
event dropped due to slow handler
.
Hey @F21!
It's a known limitation of inotify (http://man7.org/linux/man-pages/man7/inotify.7.html):
If monitoring an entire directory subtree, and a new subdirectory is
created in that tree or an existing directory is renamed into that
tree, be aware that by the time you create a watch for the new
subdirectory, new files (and subdirectories) may already exist inside
the subdirectory. Therefore, you may want to scan the contents of
the subdirectory immediately after adding the watch (and, if desired,
recursively add watches for any subdirectories that it contains).
Notify does not yet handle invalidating the cache and rescanning filesystem, however it'd be nice to have that supported.
I'm leaving the issue open to track progress on that feature.
@rjeczalik Thank you for such a nice library. How hard would you estimate adding in the scanning would be?