After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 696014 - [PATCH] g_file_copy(): Ensure G_FILE_COPY_OVERWRITE preserves permissions
[PATCH] g_file_copy(): Ensure G_FILE_COPY_OVERWRITE preserves permissions
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-03-17 22:38 UTC by Colin Walters
Modified: 2013-03-25 20:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-g_file_copy-Ensure-G_FILE_COPY_OVERWRITE-preserves-p.patch (1.63 KB, patch)
2013-03-17 22:38 UTC, Colin Walters
none Details | Review
0001-g_file_copy-Ensure-G_FILE_COPY_OVERWRITE-preserves-p.patch (4.28 KB, patch)
2013-03-25 16:44 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2013-03-17 22:38:12 UTC
We need to close the stream *before* applying the file modes, because
g_file_replace() allocates a temporary file.  At the moment we're
applying the modes to the extant file, then immediately rename()ing
over it with the default perms.

This regressed with commit 166766a89fcd173dcd6ffda11f902029928f7f28.

The real fix here is to have g_file_create_with_info() so that we can
atomically create a file with the permissions we want.
---
 gio/gfile.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
Comment 1 Colin Walters 2013-03-17 22:38:42 UTC
Created attachment 239078 [details] [review]
0001-g_file_copy-Ensure-G_FILE_COPY_OVERWRITE-preserves-p.patch
Comment 2 Colin Walters 2013-03-25 16:44:51 UTC
Created attachment 239787 [details] [review]
0001-g_file_copy-Ensure-G_FILE_COPY_OVERWRITE-preserves-p.patch

Now with test case; I verified the test case fails before the patch, and passes after.
Comment 3 Allison Karlitskaya (desrt) 2013-03-25 17:13:25 UTC
Reviewing the patch, it makes sense and looks unlikely to introduce new errors.

I can also confirm that the test case:

 - passes with the code from before the original change
 - fails after the original change
 - passes again after this fix


I'm happy to merge this before I release 2.36.0 today, but not without two +1 from r-t.  I guess Colin implicitly is the first +1.

I really agree that we should try to fix this properly with a variant of g_file_replace() that takes permissions because we have a slim race here where the file has been copied but has not received the permissions.  Probably the correct order of steps:

 - create temp file with permission 0600
 - fill the file with contents
 - apply the proper final permissions
 - rename

but that is too big of a change for now.
Comment 4 Allison Karlitskaya (desrt) 2013-03-25 20:32:29 UTC
Second +1 from frepd.