GNOME Bugzilla – Bug 696014
[PATCH] g_file_copy(): Ensure G_FILE_COPY_OVERWRITE preserves permissions
Last modified: 2013-03-25 20:33:46 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(-)
Created attachment 239078 [details] [review] 0001-g_file_copy-Ensure-G_FILE_COPY_OVERWRITE-preserves-p.patch
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.
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.
Second +1 from frepd.