add API to create files atomically
Submitted by Sven Neumann
Created attachment 256081 patch that adds G_FILE_CREATE_ATOMIC
Sometimes it is desirable to have the semantics of safe replace as implemented in glocalfileoutputstream.c for g_file_replace() also applied on file creation.
Currently if you use g_file_replace() on a local file and the destination file already exists, the file will be written atomically. So you either get the old version or the new version of the file. However if you the destination file does not exist, then a different code path is used and the file is written directly. This means that if the writing process dies for whatever reason, you may end up with an incompletely written file. It would be nice to have a way to request atomic file creation independent from the existence of the destination file.
I suggest to add a new flag to GFileCreateFlags which forces the atomic semantics on g_file_replace(). Attached is a patch that does this for g_file_replace(). If you like this approach and consider it for inclusion, I can also come up with a patch for g_file_create() so that the new flag is also respected here.
Patch 256081, "patch that adds G_FILE_CREATE_ATOMIC":