[gegl] buffer: clean swap files that match old filename pattern on startup



commit 1fd4adcf73199e44e5a1aa4528cc5508eff9fbdf
Author: Ell <ell_se yahoo com>
Date:   Sat Nov 24 11:20:32 2018 -0500

    buffer: clean swap files that match old filename pattern on startup
    
    Commit b61f9015bf19611225df9832db3cfd9ee2558fc9 changed the
    filename pattern of swap files, and limited the cleaned-up files on
    startup (or when changing the swap dir) to only those files that
    match the new pattern.
    
    Keep cleaning up files that match the old pattern too, at least for
    now, especially since GIMP has been leaving old swap files behind
    for a while.

 gegl/buffer/gegl-buffer-swap.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-swap.c b/gegl/buffer/gegl-buffer-swap.c
index 205bfe790..8ec11ae06 100644
--- a/gegl/buffer/gegl-buffer-swap.c
+++ b/gegl/buffer/gegl-buffer-swap.c
@@ -38,7 +38,14 @@
 #include "gegl-buffer-swap-private.h"
 
 
-#define SWAP_PREFIX "gegl-swap-"
+#define SWAP_PREFIX        "gegl-swap-"
+
+/* this used to be the suffix for swap files before commit
+ * b61f9015bf19611225df9832db3cfd9ee2558fc9.  let's keep
+ * cleaning files that match this suffix on startup, at least
+ * for a while.
+ */
+#define SWAP_LEGACY_SUFFIX "-shared.swap"
 
 
 /*  local function prototypes  */
@@ -238,18 +245,20 @@ gegl_buffer_swap_clean_dir (void)
 
       while ((basename = g_dir_read_name (dir)) != NULL)
         {
+          gint pid = 0;
+
           if (g_str_has_prefix (basename, SWAP_PREFIX))
-            {
-              gint pid = atoi (basename + strlen (SWAP_PREFIX));
+            pid = atoi (basename + strlen (SWAP_PREFIX));
+          else if (g_str_has_suffix (basename, SWAP_LEGACY_SUFFIX))
+            pid = atoi (basename);
 
-              if (! gegl_buffer_swap_pid_is_running (pid))
-                {
-                  gchar *path = g_build_filename (swap_dir, basename, NULL);
+          if (pid && ! gegl_buffer_swap_pid_is_running (pid))
+            {
+              gchar *path = g_build_filename (swap_dir, basename, NULL);
 
-                  g_unlink (path);
+              g_unlink (path);
 
-                  g_free (path);
-                }
+              g_free (path);
             }
          }
 


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