mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
glib: Use g_file_set_contents_full() throughout GLib and GIO
Where applicable. Where the current use of `g_file_set_contents()` seems the most appropriate, leave that in place. Signed-off-by: Philip Withnall <withnall@endlessm.com> Helps: #1302
This commit is contained in:
parent
24ed91ce33
commit
3b6460b94c
@ -830,10 +830,12 @@ keyring_generate_entry (const gchar *cookie_context,
|
||||
/* and now actually write the cookie file if there are changes (this is atomic) */
|
||||
if (changed_file)
|
||||
{
|
||||
if (!g_file_set_contents (path,
|
||||
new_contents->str,
|
||||
-1,
|
||||
error))
|
||||
if (!g_file_set_contents_full (path,
|
||||
new_contents->str,
|
||||
-1,
|
||||
G_FILE_SET_CONTENTS_CONSISTENT,
|
||||
0600,
|
||||
error))
|
||||
{
|
||||
*out_id = 0;
|
||||
*out_cookie = 0;
|
||||
|
@ -3630,7 +3630,9 @@ update_mimeapps_list (const char *desktop_id,
|
||||
data = g_key_file_to_data (key_file, &data_size, error);
|
||||
g_key_file_free (key_file);
|
||||
|
||||
res = g_file_set_contents (filename, data, data_size, error);
|
||||
res = g_file_set_contents_full (filename, data, data_size,
|
||||
G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING,
|
||||
0600, error);
|
||||
|
||||
desktop_file_dirs_invalidate_user_config ();
|
||||
|
||||
@ -3774,7 +3776,9 @@ g_desktop_app_info_set_as_default_for_extension (GAppInfo *appinfo,
|
||||
" </mime-type>\n"
|
||||
"</mime-info>\n", mimetype, extension, extension);
|
||||
|
||||
g_file_set_contents (filename, contents, -1, NULL);
|
||||
g_file_set_contents_full (filename, contents, -1,
|
||||
G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING,
|
||||
0600, NULL);
|
||||
g_free (contents);
|
||||
|
||||
run_update_command ("update-mime-database", "mime");
|
||||
@ -3923,7 +3927,9 @@ g_desktop_app_info_ensure_saved (GDesktopAppInfo *info,
|
||||
/* FIXME - actually handle error */
|
||||
(void) g_close (fd, NULL);
|
||||
|
||||
res = g_file_set_contents (filename, data, data_size, error);
|
||||
res = g_file_set_contents_full (filename, data, data_size,
|
||||
G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING,
|
||||
0600, error);
|
||||
g_free (data);
|
||||
if (!res)
|
||||
{
|
||||
|
@ -2211,7 +2211,9 @@ g_local_file_trash (GFile *file,
|
||||
original_name_escaped, delete_time);
|
||||
g_free (delete_time);
|
||||
|
||||
g_file_set_contents (infofile, data, -1, NULL);
|
||||
g_file_set_contents_full (infofile, data, -1,
|
||||
G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING,
|
||||
0600, NULL);
|
||||
|
||||
/* TODO: Maybe we should verify that you can delete the file from the trash
|
||||
* before moving it? OTOH, that is hard, as it needs a recursive scan
|
||||
|
@ -573,7 +573,9 @@ write_config_file (GTestDBus *self)
|
||||
"</busconfig>\n");
|
||||
|
||||
close (fd);
|
||||
g_file_set_contents (path, contents->str, contents->len, &error);
|
||||
g_file_set_contents_full (path, contents->str, contents->len,
|
||||
G_FILE_SET_CONTENTS_NONE,
|
||||
0600, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_string_free (contents, TRUE);
|
||||
|
@ -4611,7 +4611,9 @@ g_key_file_parse_comment_as_value (GKeyFile *key_file,
|
||||
* @error: a pointer to a %NULL #GError, or %NULL
|
||||
*
|
||||
* Writes the contents of @key_file to @filename using
|
||||
* g_file_set_contents().
|
||||
* g_file_set_contents(). If you need stricter guarantees about durability of
|
||||
* the written file than are provided by g_file_set_contents(), use
|
||||
* g_file_set_contents_full() with the return value of g_key_file_to_data().
|
||||
*
|
||||
* This function can fail for any of the reasons that
|
||||
* g_file_set_contents() may fail.
|
||||
|
@ -1552,7 +1552,7 @@ g_rmdir (const gchar *filename)
|
||||
*
|
||||
* As `close()` and `fclose()` are part of the C library, this implies that it is
|
||||
* currently impossible to close a file if the application C library and the C library
|
||||
* used by GLib are different. Convenience functions like g_file_set_contents()
|
||||
* used by GLib are different. Convenience functions like g_file_set_contents_full()
|
||||
* avoid this problem.
|
||||
*
|
||||
* Returns: A `FILE*` if the file was successfully opened, or %NULL if
|
||||
|
Loading…
Reference in New Issue
Block a user