I'm watching files for changes using inotify events (as it happens, from Python, calling into libc).
For some files during a git clone
, I see something odd: I see an IN_CREATE
event, and I see via ls
that the file has content, however, I never see IN_MODIFY
or IN_CLOSE_WRITE
. This is causing me issues since I would like to respond to IN_CLOSE_WRITE
on the files: specifically, to initiate an upload of the file contents.
The files that behave oddly are in the .git/objects/pack
directory, and they end in .pack
or .idx
. Other files that git creates have a more regular IN_CREATE
-> IN_MODIFY
-> IN_CLOSE_WRITE
chain (I'm not watching for IN_OPEN
events).
This is inside docker on MacOS, but I have seen evidence of the same on docker on Linux in a remote system, so my suspicion is the MacOS aspect is not relevant. I am seeing this if watching and git clone
are in the same docker container.
My questions:
Why are these events missing on these files?
What can be done about it? Specifically, how can I respond to the completion of writes to these files? Note: ideally I would like to respond when writing is "finished" to avoid needlessly/(incorrectly) uploading "unfinished" writing.
Edit: Reading https://developer.ibm.com/tutorials/l-inotify/ it looks like what I'm seeing is consistent with
- a separate temporary file, with name like
tmp_pack_hBV4Alz
, being created, modified and, closed; - a hard link is created to this file, with the final
.pack
name; - the original
tmp_pack_hBV4Alz
name is deleted.
I think my problem, which is trying to use inotify as a trigger to upload files, then reduces to noticing that the .pack
file is a hard link to another file, and uploading in this case?