[gnome-builder] io: add file walk variant that can ignore directories
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] io: add file walk variant that can ignore directories
- Date: Tue, 26 Mar 2019 01:32:52 +0000 (UTC)
commit 6d605a110c31c7b70141a22bf2ccfe37308f5e73
Author: Christian Hergert <chergert redhat com>
Date: Mon Mar 25 18:30:16 2019 -0700
io: add file walk variant that can ignore directories
If @ignore_file is found within @directory, then that directory
will be skipped as part of the file walking procedure. This is
a convenience API that allows pluggins to skip parts of the
project tree.
src/libide/io/ide-gfile.c | 63 ++++++++++++++++++++++++++++++++++++++++-------
src/libide/io/ide-gfile.h | 7 ++++++
2 files changed, 61 insertions(+), 9 deletions(-)
---
diff --git a/src/libide/io/ide-gfile.c b/src/libide/io/ide-gfile.c
index 7eaef19e9..75daa064b 100644
--- a/src/libide/io/ide-gfile.c
+++ b/src/libide/io/ide-gfile.c
@@ -729,11 +729,14 @@ ide_g_host_file_get_contents (const gchar *path,
}
/**
- * ide_g_file_walk:
+ * ide_g_file_walk_with_ignore:
* @directory: a #GFile that is a directory
* @attributes: attributes to include in #GFileInfo
+ * @ignore_file: (nullable): the filename within @directory to indicate that
+ * the directory should be ignored
* @cancellable: (nullable): an optional cancellable
- * @callback: (scope call): a callback for each directory starting from @directory
+ * @callback: (scope call): a callback for each directory starting from
+ * the @directory
* @callback_data: closure data for @callback
*
* Calls @callback for every directory starting from @directory.
@@ -741,14 +744,18 @@ ide_g_host_file_get_contents (const gchar *path,
* All of the fileinfo for the directory will be provided to the callback for
* each directory.
*
- * Since: 3.32
+ * If @ignore_file is set, this function will check to see if that file exists
+ * within @directory and skip it (and all descendants) if discovered.
+ *
+ * Since: 3.34
*/
void
-ide_g_file_walk (GFile *directory,
- const gchar *attributes,
- GCancellable *cancellable,
- IdeFileWalkCallback callback,
- gpointer callback_data)
+ide_g_file_walk_with_ignore (GFile *directory,
+ const gchar *attributes,
+ const gchar *ignore_file,
+ GCancellable *cancellable,
+ IdeFileWalkCallback callback,
+ gpointer callback_data)
{
g_autoptr(GFileEnumerator) enumerator = NULL;
g_autoptr(GPtrArray) directories = NULL;
@@ -776,6 +783,14 @@ ide_g_file_walk (GFile *directory,
if (directory_type != G_FILE_TYPE_DIRECTORY)
return;
+ if (ignore_file != NULL)
+ {
+ g_autoptr(GFile) ignore = g_file_get_child (directory, ignore_file);
+
+ if (g_file_query_exists (ignore, cancellable))
+ return;
+ }
+
str = g_string_new (attributes);
for (guint i = 0; required[i]; i++)
@@ -819,6 +834,36 @@ ide_g_file_walk (GFile *directory,
if (g_cancellable_is_cancelled (cancellable))
break;
- ide_g_file_walk (child, attributes, cancellable, callback, callback_data);
+ ide_g_file_walk_with_ignore (child,
+ attributes,
+ ignore_file,
+ cancellable,
+ callback,
+ callback_data);
}
}
+
+/**
+ * ide_g_file_walk:
+ * @directory: a #GFile that is a directory
+ * @attributes: attributes to include in #GFileInfo
+ * @cancellable: (nullable): an optional cancellable
+ * @callback: (scope call): a callback for each directory starting from @directory
+ * @callback_data: closure data for @callback
+ *
+ * Calls @callback for every directory starting from @directory.
+ *
+ * All of the fileinfo for the directory will be provided to the callback for
+ * each directory.
+ *
+ * Since: 3.32
+ */
+void
+ide_g_file_walk (GFile *directory,
+ const gchar *attributes,
+ GCancellable *cancellable,
+ IdeFileWalkCallback callback,
+ gpointer callback_data)
+{
+ ide_g_file_walk_with_ignore (directory, attributes, NULL, cancellable, callback, callback_data);
+}
diff --git a/src/libide/io/ide-gfile.h b/src/libide/io/ide-gfile.h
index e728b5db4..db631c3fe 100644
--- a/src/libide/io/ide-gfile.h
+++ b/src/libide/io/ide-gfile.h
@@ -94,5 +94,12 @@ void ide_g_file_walk (GFile *direc
GCancellable *cancellable,
IdeFileWalkCallback callback,
gpointer callback_data);
+IDE_AVAILABLE_IN_3_34
+void ide_g_file_walk_with_ignore (GFile *directory,
+ const gchar *attributes,
+ const gchar *ignore_file,
+ GCancellable *cancellable,
+ IdeFileWalkCallback callback,
+ gpointer callback_data);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]