GNOME Bugzilla – Bug 594034
Add API g_mkstemp_full() to fix issues with g_file_replace()
Last modified: 2009-09-08 09:17:57 UTC
See the comments for the attachments for details
Created attachment 142405 [details] [review] Add g_mkstemp_full() This function exposes more variables than g_mkstemp() and therefor allows more flexibility when creating temporary files. The intended use is gio's code for g_file_replace() (see next patch)
Created attachment 142406 [details] [review] Use g_mkstemp_full() when creating the replacement file Previous code used g_mkstemp(). But when using G_FILE_CREATE_REPLACE_DESTINATION, no attempt was made to ensure proper mode and flags of the created temporary file. The visible issue was that the file was always created with mode 0600 as opposed to using 0666. (The invisible issue was that O_RDWR was used instead of O_WRONLY.)
Hmm, will we also grow a g_file_open_tmp_full() ? Or should we have only one or only the other ?
I'd have used g_file_open_tmp() instead, but the problem is that that function returns a G_FILE_ERROR and g_file_replace() returns a G_IO_ERROR. So unless I want to comeup with a huge conversion table, I have to use g_mkstemp(). The other option is to just copy the function to gio and keep it there. But as it's used by g_file_set_contents, too, it seemed like useful API to me.
Ok then, go ahead. No point in hesitating for weeks over the name...
This has been committed in 24bec5c5bd64eb829a433e4c1e8d34dc25879a64 and 4114f1214c65f0a142678bf98b1d8e4da43bf665 and has been part of glib 2.21.6.