I am using
inotify (implemented via
pyinotify) on my Ubuntu 18.4 system in order to monitor creates, modifies, and attribute changes in certain directories.
I use these watch flags: IN_CREATE, IN_MOVED_TO, IN_MOVED_FROM, IN_MODIFY, and IN_ATTRIB
One of the things I do when
inotify notices one of these changes to a file is to do a
chmod and sometimes even a
chown on the file. For example, if the modification date of one of these watched files changes (e.g., via a
touch command), or if the size of the file changes, I will perform a
chmod and possibly a
chown on that file.
However, with the IN_ATTRIB watch flag, the
chown flags trigger another IN_ATTRIB change, and this results in my re-issuing the command, which in turn causes the file to be noticed again and again by IN_ATTRIB, resulting in a loop of identical changes.
I want to avoid this. One way I know I could do it is to check the permissions and ownership before issuing
chown, and only run either of those if a change is really needed. However, I'm wondering if there is a way in
pyinotify) to cause a change being made in the watcher program to be ignored.
I know that I can temporarily disable watching that one particular file, but then I have to re-enable watching it at some point, in case there is another need to modify the file.
Aside from checking the permissions and ownership before issuing
chown, is there a way to accomplish what I'm trying to do?
Thank you in advance.