[gimp] app: change gimp_config_file_backup_on_error() to take a GFile



commit 3665352ad6dbe020fbc82362e48711b50399d9c4
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 1 20:02:13 2014 +0200

    app: change gimp_config_file_backup_on_error() to take a GFile

 app/config/gimpconfig-file.c |   11 +++++++----
 app/config/gimpconfig-file.h |    9 +++++----
 app/config/gimprc.c          |    6 +++++-
 app/core/gimp-units.c        |    6 +-----
 app/gui/session.c            |    6 +-----
 5 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/app/config/gimpconfig-file.c b/app/config/gimpconfig-file.c
index 20cf940..0d425ef 100644
--- a/app/config/gimpconfig-file.c
+++ b/app/config/gimpconfig-file.c
@@ -211,20 +211,22 @@ gimp_config_file_copy (const gchar         *source,
 }
 
 gboolean
-gimp_config_file_backup_on_error (const gchar  *filename,
+gimp_config_file_backup_on_error (GFile        *file,
                                   const gchar  *name,
                                   GError      **error)
 {
+  gchar    *path;
   gchar    *backup;
   gboolean  success;
 
-  g_return_val_if_fail (filename != NULL, FALSE);
+  g_return_val_if_fail (G_IS_FILE (file), FALSE);
   g_return_val_if_fail (name != NULL, FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  backup = g_strconcat (filename, "~", NULL);
+  path   = g_file_get_path (file);
+  backup = g_strconcat (path, "~", NULL);
 
-  success = gimp_config_file_copy (filename, backup, NULL, NULL, error);
+  success = gimp_config_file_copy (path, backup, NULL, NULL, error);
 
   if (success)
     g_message (_("There was an error parsing your '%s' file. "
@@ -233,6 +235,7 @@ gimp_config_file_backup_on_error (const gchar  *filename,
                name, gimp_filename_to_utf8 (backup));
 
   g_free (backup);
+  g_free (path);
 
   return success;
 }
diff --git a/app/config/gimpconfig-file.h b/app/config/gimpconfig-file.h
index 2ffc732..80c49ea 100644
--- a/app/config/gimpconfig-file.h
+++ b/app/config/gimpconfig-file.h
@@ -26,10 +26,11 @@ gboolean   gimp_config_file_copy             (const gchar        *source,
                                               const gchar        *dest,
                                               const gchar        *old_options_regexp,
                                               GRegexEvalCallback  update_callback,
-                                              GError      **error);
-gboolean   gimp_config_file_backup_on_error  (const gchar  *filename,
-                                              const gchar  *name,
-                                              GError      **error);
+                                              GError            **error);
+
+gboolean   gimp_config_file_backup_on_error  (GFile              *file,
+                                              const gchar        *name,
+                                              GError            **error);
 
 
 #endif  /* __GIMP_CONFIG_FILE_H__ */
diff --git a/app/config/gimprc.c b/app/config/gimprc.c
index 3d62539..c9a15a2 100644
--- a/app/config/gimprc.c
+++ b/app/config/gimprc.c
@@ -277,9 +277,13 @@ gimp_rc_load (GimpRc *rc)
     {
       if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
         {
+          GFile *file;
+
           g_message ("%s", error->message);
 
-          gimp_config_file_backup_on_error (rc->user_gimprc, "gimprc", NULL);
+          file = g_file_new_for_path (rc->user_gimprc);
+          gimp_config_file_backup_on_error (file, "gimprc", NULL);
+          g_object_unref (file);
         }
 
       g_clear_error (&error);
diff --git a/app/core/gimp-units.c b/app/core/gimp-units.c
index 8032854..cdb8bd8 100644
--- a/app/core/gimp-units.c
+++ b/app/core/gimp-units.c
@@ -167,8 +167,6 @@ gimp_unitrc_load (Gimp *gimp)
 
   if (token != G_TOKEN_LEFT_PAREN)
     {
-      gchar *tmp;
-
       g_scanner_get_next_token (scanner);
       g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                              _("fatal parse error"), TRUE);
@@ -176,9 +174,7 @@ gimp_unitrc_load (Gimp *gimp)
       gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_clear_error (&error);
 
-      tmp = g_file_get_path (file);
-      gimp_config_file_backup_on_error (tmp, "unitrc", NULL);
-      g_free (tmp);
+      gimp_config_file_backup_on_error (file, "unitrc", NULL);
     }
 
   gimp_scanner_destroy (scanner);
diff --git a/app/gui/session.c b/app/gui/session.c
index d6349d3..c8e366c 100644
--- a/app/gui/session.c
+++ b/app/gui/session.c
@@ -298,14 +298,10 @@ session_init (Gimp *gimp)
 
   if (error)
     {
-      gchar *tmp;
-
       gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_clear_error (&error);
 
-      tmp = g_file_get_path (file);
-      gimp_config_file_backup_on_error (tmp, "sessionrc", NULL);
-      g_free (tmp);
+      gimp_config_file_backup_on_error (file, "sessionrc", NULL);
     }
 
   gimp_scanner_destroy (scanner);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]