notify icon indicating copy to clipboard operation
notify copied to clipboard

Recursive watches on Linux reports wrong directories if directories are renamed.

Open F21 opened this issue 8 years ago • 2 comments

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:

  1. Create folder test using the file manager (nautilus).
  2. Within test create another folder called test-child using the file manager.
  3. Within test-child, create test-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:

  1. When a folder is first created, the file manager names it Untitled Folder. Even though we assign the folder's name to be test, the notifier still returns Untitled Folder in the event's path when a descendent changes.
  2. Notifier seems to not detect changes at the third level (test-grand-child) and produces no events.
  3. I tried changing the event channel buffer to 100, but it still warns about event dropped due to slow handler.

F21 avatar Mar 10 '16 08:03 F21

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 avatar Mar 12 '16 21:03 rjeczalik

@rjeczalik Thank you for such a nice library. How hard would you estimate adding in the scanning would be?

thejacobtaylor avatar Oct 25 '16 04:10 thejacobtaylor