I’m working in ubuntu and need to monitor a directory tree for new subdirectories and files. These are populated by rsync; dozens of subdirectories and hundreds of files may be added in less than one second. I’m considering a few options:
option 1: Monitor the tree with python’s inotify.adapters.InotifyTree(). But the documentation contains this caveat: "IMPORTANT: Recursively monitoring paths is not a functionality provided by the kernel. Rather, we artificially implement it. As directory-created events are received, we create watches for the child directories on-the-fly. This means that there is potential for a race condition: if a directory is created and a file or directory is created inside before you (using the event_gen() loop) have a chance to observe it, then you are going to have a problem: If it is a file, then you will miss the events related to its creation, but, if it is a directory, then not only will you miss those creation events but this library will also miss them and not be able to add a watch for them."
option 2: Monitor the tree with the linux inotifywatch utility using the ‘--recursive’ option. That documentation includes this caveat: "Warning: If you use this option while watching the root directory of a large tree, it may take quite a while until all inotify watches are established, and events will not be received in this time."
Which of these two options do you think is less likely to miss new subdirectories and files? My sense is that option 2 is probably more reliable since inotifywatch is (probably) implemented in ‘C’. Thanks!
inotify
functionality. More code, more bugs.