[gnome-builder] io: add synchronous form of find_with_depth



commit 271486a443fb965e9088bc43b65c50e4ac2e6c44
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 17 21:22:33 2019 -0800

    io: add synchronous form of find_with_depth
    
    This allows usage from a worker thread, which can be convenient to avoid
    spawning a secondary worker thread.

 src/libide/io/ide-gfile.c | 38 ++++++++++++++++++++++++++++++++++++++
 src/libide/io/ide-gfile.h |  5 +++++
 2 files changed, 43 insertions(+)
---
diff --git a/src/libide/io/ide-gfile.c b/src/libide/io/ide-gfile.c
index 22148bc9c..6cd4fbd6d 100644
--- a/src/libide/io/ide-gfile.c
+++ b/src/libide/io/ide-gfile.c
@@ -514,6 +514,44 @@ ide_g_file_find_worker (IdeTask      *task,
   ide_task_return_pointer (task, g_steal_pointer (&ret), (GDestroyNotify)g_ptr_array_unref);
 }
 
+/**
+ * ide_g_file_find_with_depth:
+ * @file: a #GFile
+ * @pattern: the glob pattern to search for using GPatternSpec
+ * @max_depth: maximum tree depth to search
+ * @cancellable: (nullable): a #GCancellable or %NULL
+ *
+ *
+ * Returns: (transfer full) (element-type GFile): a #GPtrArray of #GFile.
+ *
+ * Since: 3.32
+ */
+GPtrArray *
+ide_g_file_find_with_depth (GFile        *file,
+                            const gchar  *pattern,
+                            guint         max_depth,
+                            GCancellable *cancellable)
+{
+  g_autoptr(GPatternSpec) spec = NULL;
+  GPtrArray *ret;
+
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
+  g_return_val_if_fail (pattern != NULL, NULL);
+
+  if (!(spec = g_pattern_spec_new (pattern)))
+    {
+      g_warning ("Failed to build pattern spec for \"%s\"", pattern);
+      return NULL;
+    }
+
+  if (max_depth == 0)
+    max_depth = G_MAXUINT;
+
+  ret = g_ptr_array_new ();
+  populate_descendants_matching (file, cancellable, ret, spec, max_depth);
+  return IDE_PTR_ARRAY_STEAL_FULL (&ret);
+}
+
 /**
  * ide_g_file_find_with_depth_async:
  * @file: a #IdeGlib
diff --git a/src/libide/io/ide-gfile.h b/src/libide/io/ide-gfile.h
index 250fec772..f5f5f46a2 100644
--- a/src/libide/io/ide-gfile.h
+++ b/src/libide/io/ide-gfile.h
@@ -38,6 +38,11 @@ IDE_AVAILABLE_IN_3_32
 gchar     *ide_g_file_get_uncanonical_relative_path (GFile                *file,
                                                      GFile                *other);
 IDE_AVAILABLE_IN_3_32
+GPtrArray *ide_g_file_find_with_depth               (GFile                *file,
+                                                     const gchar          *pattern,
+                                                     guint                 max_depth,
+                                                     GCancellable         *cancellable);
+IDE_AVAILABLE_IN_3_32
 void       ide_g_file_find_with_depth_async         (GFile                *file,
                                                      const gchar          *pattern,
                                                      guint                 max_depth,


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