In my backup app I am monitoring changes to a user-selected directory A and mirroring all file changes to another directory B. The only problem seems to be: how do I know if a file has been created and is still being written to, such as when an app creates a very big file or the Finder copies a file?
I would like to ignore this event because another event will follow corresponding to the moment in which the write operation has finished and it is almost certainly safe to copy the file from A to B (starting a copy while the original file is still being written usually results in an error). I tried to analyze the flags passed to the FSEvents callback, but it seems like different applications cause different flags to be passed (for instance the cp and touch commands, a copy initiated in the Finder, creating a file from TextEdit and Word all result in different flags).