]> spindle.queued.net Git - midori/commitdiff
Use g_file_set_contents to save 'config' with a temporary file
authorChristian Dywan <christian@twotoasts.de>
Thu, 10 Jun 2010 15:49:22 +0000 (17:49 +0200)
committerChristian Dywan <christian@twotoasts.de>
Thu, 10 Jun 2010 15:54:44 +0000 (17:54 +0200)
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

index 04c37af5a14ef3a94a264a84a5c862fe56347494..e8ade3af89eb5c403e17f8891e3a23daba4a8a6c 100644 (file)
@@ -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