0

I have this simple python program in script.py.

import os

os.mkdir('abc')

with open('abc/readme.txt', 'w') as f:
  f.write('Sample text file')

os.rename('abc', 'new_folder')

Now, on a separate terminal, I ran this inotifywait command. This monitors the current directory recursively. inotifywait -qrme modify,attrib,move,create,delete,access .

Then while monitoring, I ran the python program above which gives me these events:

./ ACCESS script.py
./ ACCESS script.py
./ ACCESS,ISDIR 
./ CREATE,ISDIR abc
./ MOVED_FROM,ISDIR abc
./ MOVED_TO,ISDIR new_folder
./ ACCESS,ISDIR new_folder
./ ACCESS,ISDIR 
./ ACCESS,ISDIR new_folder
./new_folder/ ACCESS,ISDIR 
./ ACCESS,ISDIR new_folder
./new_folder/ ACCESS,ISDIR 
./ ACCESS,ISDIR 
./ ACCESS,ISDIR 
./ ACCESS,ISDIR 

As you have observed, the create and modify events for abc/readme.txt did not show up.

Now, I understand that this is due to race conditions as stated in their docs. However, my question is, is there a workaround for this?

Assumptions and constraints in this problem:

  1. Strictly, only one level of directories from the root directory are created. Meaning, /folder1/folder2/ is not possible.
  2. I cannot modify the program.
  3. I know what directories are going to be created in the root directory.

0 Answers0