gegl r2704 - in trunk: . gegl



Author: ok
Date: Sat Nov  8 15:33:38 2008
New Revision: 2704
URL: http://svn.gnome.org/viewvc/gegl?rev=2704&view=rev

Log:
* gegl/gegl-init.c: (pid_is_running), (swap_clean), (gegl_exit),
(gegl_post_parse_hook): Made GEGL clean up the swap dir on launch
for all swap files belonging to non running processes, also fixed
the glob used to find the current process' swaps.


Modified:
   trunk/ChangeLog
   trunk/gegl/gegl-init.c

Modified: trunk/gegl/gegl-init.c
==============================================================================
--- trunk/gegl/gegl-init.c	(original)
+++ trunk/gegl/gegl-init.c	Sat Nov  8 15:33:38 2008
@@ -252,6 +252,49 @@
 #endif
 void gegl_tile_backend_file_stats (void);
 
+static gboolean
+pid_is_running (gint pid)
+{
+  gchar buf[512];
+  g_sprintf (buf, "/proc/%i", pid);
+  return g_file_test (buf, G_FILE_TEST_EXISTS);
+}
+
+
+static void swap_clean (void)
+{ 
+  GDir         *dir     = g_dir_open (gegl_swap_dir (), 0, NULL);
+  gchar        *glob    = g_strdup_printf ("*");
+  GPatternSpec *pattern = g_pattern_spec_new (glob);
+  g_free (glob);
+
+  if (dir != NULL)
+    {
+      const gchar *name;
+
+      while ((name = g_dir_read_name (dir)) != NULL)
+        {
+          if (g_pattern_match_string (pattern, name))
+            {
+              gint readpid = atoi (name);
+                  
+              if (!pid_is_running (readpid))
+                {
+                  gchar *fname = g_build_filename (gegl_swap_dir (),
+                                                       name,
+                                                       NULL);
+                  g_unlink (fname);
+                  g_free (fname);
+                }
+            }
+         }
+       g_dir_close (dir);
+    }
+
+ g_pattern_spec_free (pattern);
+}
+
+
 void
 gegl_exit (void)
 {
@@ -301,7 +344,7 @@
       guint         pid     = getpid ();
       GDir         *dir     = g_dir_open (gegl_swap_dir (), 0, NULL);
 
-      gchar        *glob    = g_strdup_printf ("GEGL-%i-*.swap", pid);
+      gchar        *glob    = g_strdup_printf ("%i-*", pid);
       GPatternSpec *pattern = g_pattern_spec_new (glob);
       g_free (glob);
 
@@ -332,6 +375,7 @@
   g_print ("\n");
 }
 
+static void swap_clean (void);
 
 
 static void
@@ -486,6 +530,7 @@
         g_object_set (config, "quality", 1.0, NULL);
     }
 
+  swap_clean ();
   return TRUE;
 }
 



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