efsw
efsw copied to clipboard
inotify monitor doesn't reliably detect fast recursive file creation
I'm attempting to use this library (on Linux) to recursively watch real time creation of .git/objects
when users interact with their repository.
Upon commands such as git add
and git commit
, git
creates subirectories in .git/objects/
, and immediately after creates a file in that subdirectory such as .git/objects/47/c83adec4eb349f06d8e5fea7373d97f0e8ed84
.
I noticed this library detects this file creation most of the time, but not always.
It's a bit hard to reproduce because I believe it's a race condition.
My understanding of inotify
is that it doesn't support recursive watches, so you have to establish watches on subdirectories yourself.
If a file is created very quickly in that newly created subdirectory, then you might miss it because you haven't established the new watch yet.
I opened https://github.com/emcrisostomo/fswatch/issues/330, and their approach was to scan newly watched directories and emit a "synthetic event" following a similar approach to inotify-wait
(see https://github.com/inotify-tools/inotify-tools/issues/121).