Make GSettings keyfile backend not overwrite the mode and permissions of settings file
Currently, when a GSettings object is created with g_keyfile_settings_backend_new()
and a key is written with g_settings_set_value()
, file permissions and mode are overwritten in case the file already exists.
This is due to the fact that the settings file is replaced with:
success = g_file_replace_contents (kfsb->file, contents, length, NULL, FALSE,
G_FILE_CREATE_REPLACE_DESTINATION |
G_FILE_CREATE_PRIVATE,
NULL, NULL, error);
and REPLACE_DESTINATION
overrides the mode and permissions (reference: https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/gkeyfilesettingsbackend.c#L119-122).
For many use cases it is useful to keep the file original permissions and owner, e.g. for a world-readable file written by root we want to keep the read permissions, so I would like to make this behavior configurable (e.g. by overriding the flags set when replacing the file content).
Related to: #1658 (closed)