[Xfce4-commits] <exo:master> Use g_file_set_contents on local files.

Nick Schermer noreply at xfce.org
Mon Apr 2 20:24:01 CEST 2012


Updating branch refs/heads/master
         to 44313c58da0eceb305f4bc1e9f2255900f0f2838 (commit)
       from 04f9a8d328353b53723cfd965731fa65bd0b0d63 (commit)

commit 44313c58da0eceb305f4bc1e9f2255900f0f2838
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Apr 2 20:21:49 2012 +0200

    Use g_file_set_contents on local files.
    
    Advantage is that g_file_set_contents always uses a tmp
    file and then moves the file. The gio version doesn't
    which causes a file-created reply in the panel, but without
    contents, resulting in no new launcher.

 exo-desktop-item-edit/exo-die-utils.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/exo-desktop-item-edit/exo-die-utils.c b/exo-desktop-item-edit/exo-die-utils.c
index 8434ddf..f2af0b7 100644
--- a/exo-desktop-item-edit/exo-die-utils.c
+++ b/exo-desktop-item-edit/exo-die-utils.c
@@ -99,6 +99,7 @@ exo_die_g_key_file_save (GKeyFile          *key_file,
   guint        n;
   gboolean     desktop_suffix;
   const gchar *suffix;
+  gchar       *path;
 
   g_return_val_if_fail (G_IS_FILE (base), FALSE);
   g_return_val_if_fail (key_file != NULL, FALSE);
@@ -185,13 +186,21 @@ exo_die_g_key_file_save (GKeyFile          *key_file,
     }
 
   /* write the contents to the file */
-  result = g_file_replace_contents (file, data, length, NULL, FALSE,
-#if GLIB_CHECK_VERSION (2, 20, 0)
-                                    G_FILE_CREATE_REPLACE_DESTINATION,
-#else
-                                    G_FILE_CREATE_NONE,
-#endif
-                                    NULL, NULL, error);
+  if (g_file_is_native (file))
+    {
+      /* for local writes, to make sure the file is written to a tmp
+       * file before the origional desktop file is replaced */
+      path = g_file_get_path (file);
+      result = g_file_set_contents (path, data, length, error);
+      g_free (path);
+    }
+  else
+    {
+      /* for remote writes */
+      result = g_file_replace_contents (file, data, length, NULL, FALSE,
+                                        G_FILE_CREATE_REPLACE_DESTINATION,
+                                        NULL, NULL, error);
+    }
 
   /* cleanup */
   g_free (data);


More information about the Xfce4-commits mailing list