[gegl] buffer: add gegl_buffer_swap_has_file()



commit 1597e17db08bbe541baa71a113cb5a7b6d0a1f06
Author: Ell <ell_se yahoo com>
Date:   Mon Dec 17 06:50:28 2018 -0500

    buffer: add gegl_buffer_swap_has_file()
    
    ... which checks if a given file is a swap file, that is, if it has
    been created with gegl_buffer_swap_create_file(), and hasn't been
    removed yet.

 gegl/buffer/gegl-buffer-swap.c | 16 ++++++++++++++++
 gegl/buffer/gegl-buffer-swap.h | 14 ++++++++++++--
 2 files changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-swap.c b/gegl/buffer/gegl-buffer-swap.c
index 8ec11ae06..6f0b29e10 100644
--- a/gegl/buffer/gegl-buffer-swap.c
+++ b/gegl/buffer/gegl-buffer-swap.c
@@ -174,6 +174,22 @@ gegl_buffer_swap_remove_file (const gchar *path)
     g_warning ("attempt to remove unregistered swap file '%s'", path);
 }
 
+gboolean
+gegl_buffer_swap_has_file (const gchar *path)
+{
+  gboolean found;
+
+  g_return_val_if_fail (path != NULL, FALSE);
+
+  g_mutex_lock (&swap_mutex);
+
+  found = (g_hash_table_lookup (swap_files, path) != NULL);
+
+  g_mutex_unlock (&swap_mutex);
+
+  return found;
+}
+
 
 /*  private functions  */
 
diff --git a/gegl/buffer/gegl-buffer-swap.h b/gegl/buffer/gegl-buffer-swap.h
index 8e6ca074d..1223212fc 100644
--- a/gegl/buffer/gegl-buffer-swap.h
+++ b/gegl/buffer/gegl-buffer-swap.h
@@ -37,7 +37,7 @@ G_BEGIN_DECLS
  * file path, or %NULL is the swap is disabled.  The returned string
  * should be freed with g_free() when no longer needed.
  */
-gchar * gegl_buffer_swap_create_file (const gchar *suffix);
+gchar    * gegl_buffer_swap_create_file (const gchar *suffix);
 
 /**
  * gegl_buffer_swap_remove_file:
@@ -47,7 +47,17 @@ gchar * gegl_buffer_swap_create_file (const gchar *suffix);
  * Removes a swap file, generated using gegl_buffer_swap_create_file(),
  * unlinking the file, if exists.
  */
-void    gegl_buffer_swap_remove_file (const gchar *path);
+void       gegl_buffer_swap_remove_file (const gchar *path);
+
+/**
+ * gegl_buffer_swap_has_file:
+ * @path: (type filename): a filename
+ *
+ * Tests if @path is a swap file, that is, if it has been created
+ * with gegl_buffer_swap_create_file(), and hasn't been removed
+ * yet.
+ */
+gboolean   gegl_buffer_swap_has_file (const gchar *path);
 
 G_END_DECLS
 


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