[Xfce4-commits] <midori:master> Use g_file_set_contents to save 'config' with a temporary file

Christian Dywan noreply at xfce.org
Thu Jun 10 17:56:01 CEST 2010


Updating branch refs/heads/master
         to ff6fec636700b71b296ebe5c2976b8cb7080d292 (commit)
       from 5333845ba45e2c709e50418ee28310b9693b648f (commit)

commit ff6fec636700b71b296ebe5c2976b8cb7080d292
Author: Christian Dywan <christian at twotoasts.de>
Date:   Thu Jun 10 17:49:22 2010 +0200

    Use g_file_set_contents to save 'config' with a temporary file
    
    If the filesystem runs out of space and Midori tries to save
    the 'config' file under that condition, the file is lost. To
    avoid that, we use g_file_set_contents which writes a temporary
    file first, at the cost of destroying symbolic links.

 midori/sokoke.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/midori/sokoke.c b/midori/sokoke.c
index 04c37af..e8ade3a 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -1103,22 +1103,15 @@ sokoke_key_file_save_to_file (GKeyFile*    key_file,
                               GError**     error)
 {
     gchar* data;
-    FILE* fp;
+    gboolean success = FALSE;
 
     data = g_key_file_to_data (key_file, NULL, error);
     if (!data)
         return FALSE;
 
-    if (!(fp = fopen (filename, "w")))
-    {
-        *error = g_error_new (G_FILE_ERROR, G_FILE_ERROR_ACCES,
-                              _("Writing failed."));
-        return FALSE;
-    }
-    fputs (data, fp);
-    fclose (fp);
+    success = g_file_set_contents (filename, data, -1, error);
     g_free (data);
-    return TRUE;
+    return success;
 }
 
 void



More information about the Xfce4-commits mailing list