[gimp] app: do not allocate a GFile when crashing.



commit 802ba92ca5e37ef57b2dc6763e025cb6dd0762e5
Author: Jehan <jehan girinstud io>
Date:   Thu Jul 30 15:53:54 2020 +0200

    app: do not allocate a GFile when crashing.
    
    When backup-ing images upon crashing, reuse a GFile allocated at
    startup, and simply rename the file to handle multiple files to save.

 app/errors.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/app/errors.c b/app/errors.c
index ad819d35ea..1c57814807 100644
--- a/app/errors.c
+++ b/app/errors.c
@@ -92,6 +92,7 @@ static GimpStackTraceMode   stack_trace_mode  = GIMP_STACK_TRACE_QUERY;
 static gchar               *full_prog_name    = NULL;
 static gchar               *backtrace_file    = NULL;
 static gchar               *backup_path       = NULL;
+static GFile               *backup_file       = NULL;
 static guint                log_domain_handler_ids[G_N_ELEMENTS (log_domains)];
 static guint                gegl_handler_id   = 0;
 static guint                global_handler_id = 0;
@@ -151,6 +152,8 @@ errors_init (Gimp               *gimp,
   backup_path = g_build_filename (gimp_directory (), "backups",
                                   "backup-XXX.xcf", NULL);
 
+  backup_file = g_file_new_for_path (backup_path);
+
   for (i = 0; i < G_N_ELEMENTS (log_domains); i++)
     log_domain_handler_ids[i] = g_log_set_handler (log_domains[i],
                                                    G_LOG_LEVEL_WARNING |
@@ -187,6 +190,8 @@ errors_exit (void)
     g_free (full_prog_name);
   if (backup_path)
     g_free (backup_path);
+  if (backup_file)
+    g_object_unref (backup_file);
 }
 
 GList *
@@ -496,8 +501,9 @@ gimp_eek (const gchar *reason,
                                               GIMP_TYPE_IMAGE,        image,
                                               G_TYPE_INT,             0,
                                               GIMP_TYPE_OBJECT_ARRAY, NULL,
-                                              G_TYPE_FILE,            g_file_new_for_path (backup_path),
+                                              G_TYPE_FILE,            backup_file,
                                               G_TYPE_NONE);
+          g_rename (g_file_peek_path (backup_file), backup_path);
           i++;
         }
     }


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