Bug 594034 - Add API g_mkstemp_full() to fix issues with g_file_replace()
Add API g_mkstemp_full() to fix issues with g_file_replace()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2009-09-03 13:47 UTC by Benjamin Otte (Company)
Modified: 2009-09-08 09:17 UTC (History)
1 user (show)

See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add g_mkstemp_full() (5.27 KB, patch)
2009-09-03 13:47 UTC, Benjamin Otte (Company)
none Details | Diff | Review
Use g_mkstemp_full() when creating the replacement file (1.14 KB, patch)
2009-09-03 13:47 UTC, Benjamin Otte (Company)
none Details | Diff | Review

Description Benjamin Otte (Company) 2009-09-03 13:47:15 UTC
See the comments for the attachments for details
Comment 1 Benjamin Otte (Company) 2009-09-03 13:47:17 UTC
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)
Comment 2 Benjamin Otte (Company) 2009-09-03 13:47:24 UTC
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.)
Comment 3 Matthias Clasen 2009-09-03 18:21:53 UTC
Hmm, will we also grow a g_file_open_tmp_full() ? Or should we have only one or only the other ?
Comment 4 Benjamin Otte (Company) 2009-09-03 19:42:34 UTC
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.
Comment 5 Matthias Clasen 2009-09-03 22:21:00 UTC
Ok then, go ahead. No point in hesitating for weeks over the name...
Comment 6 Benjamin Otte (Company) 2009-09-08 09:17:57 UTC
This has been committed in 24bec5c5bd64eb829a433e4c1e8d34dc25879a64 and 4114f1214c65f0a142678bf98b1d8e4da43bf665 and has been part of glib 2.21.6.

Note You need to log in before you can comment on or make changes to this bug.