0

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 atouch 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 chmod and 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 chmod or chown, and only run either of those if a change is really needed. However, I'm wondering if there is a way in inotify (or 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 chmod or chown, is there a way to accomplish what I'm trying to do?

Thank you in advance.

1

Given that I have gotten no responses, and given that further investigation yielded no info about how to get inotify to ignore changes that it makes itself to files and directories, I am now assuming that there is no way to do this, short of coding logic in my watch routines to not actually make calls to things like chmod and chown unless the attributes or ownership are actually currently different from the intended values.

This requires lots of extra logic in my code, but it also solves the problem.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.