I found that the Inotify class is not doing a great job in single file monitoring.
According to man inotify :
IN_IGNORED
Watch was removed explicitly (inotify_rm_watch(2)) or auto‐
matically (file was deleted, or filesystem was unmounted).
The event IN_IGNORED is generated when a watch has been automatically removed, this happens when the monitored file is removed, and it also happens when user modify the monitored file with text editors that will replace the original file while saving (such as vim).
But the Inotify class itself doesn't handle this event, so the consequence is: when this happens, the watch has been automatically removed by the kernel but it still exists in the Inotify class (in Inotify.__watches and Inotify.__watches_r), and this causes a bug, when a monitored file is removed/replaced, users can no long re-add it back into the monitoring, if they try to remove it first by calling Inotify.remove_watch() then the system call inotify_rm_watch() will return an error because the watch does not exist in the kernel space.
So, the thing I've done is giving users an optional argument to make the Inotify class handle the IN_IGNORED event and it's disabled by default.
And I changed the usage of superficial parameter in Inotify.remove_watch as well which was not being used.
Hi, I reverted the original commit and did what you asked, but beware, this changes the default behavior of Inotify class and could bring some backward compatibility issue.
Hi,
I found that the
Inotify
class is not doing a great job in single file monitoring.According to
man inotify
:The event
IN_IGNORED
is generated when a watch has been automatically removed, this happens when the monitored file is removed, and it also happens when user modify the monitored file with text editors that will replace the original file while saving (such asvim
).But the
Inotify
class itself doesn't handle this event, so the consequence is: when this happens, the watch has been automatically removed by the kernel but it still exists in theInotify
class (inInotify.__watches
andInotify.__watches_r
), and this causes a bug, when a monitored file is removed/replaced, users can no long re-add it back into the monitoring, if they try to remove it first by callingInotify.remove_watch()
then the system callinotify_rm_watch()
will return an error because the watch does not exist in the kernel space.So, the thing I've done is giving users an optional argument to make the
Inotify
class handle theIN_IGNORED
event and it's disabled by default.And I changed the usage of
superficial
parameter inInotify.remove_watch
as well which was not being used.