[tracker/miner-fs-refactor: 95/127] libtracker-miner: Add tracker_file_system_delete_files()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-fs-refactor: 95/127] libtracker-miner: Add tracker_file_system_delete_files()
- Date: Mon, 5 Dec 2011 13:27:36 +0000 (UTC)
commit 13ea72bffb80ea1ab4284c4b386c1383958c5ecc
Author: Carlos Garnacho <carlos lanedo com>
Date: Thu Oct 20 13:50:52 2011 +0200
libtracker-miner: Add tracker_file_system_delete_files()
This function recursively deletes files of a given GFileType,
or every file if G_FILE_TYPE_UNKNOWN.
src/libtracker-miner/tracker-file-system.c | 52 ++++++++++++++++++++++++++++
src/libtracker-miner/tracker-file-system.h | 4 ++
2 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-system.c b/src/libtracker-miner/tracker-file-system.c
index dc7db57..4da92c4 100644
--- a/src/libtracker-miner/tracker-file-system.c
+++ b/src/libtracker-miner/tracker-file-system.c
@@ -758,3 +758,55 @@ tracker_file_system_unset_property (TrackerFileSystem *file_system,
g_array_remove_index (data->properties, index);
}
+
+typedef struct {
+ TrackerFileSystem *file_system;
+ GList *list;
+ GFileType file_type;
+} DeleteFilesData;
+
+static gboolean
+append_deleted_files (GNode *node,
+ gpointer user_data)
+{
+ DeleteFilesData *data;
+ FileNodeData *node_data;
+
+ data = user_data;
+ node_data = node->data;
+
+ if (data->file_type == G_FILE_TYPE_UNKNOWN ||
+ node_data->file_type == data->file_type) {
+ data->list = g_list_prepend (data->list, node_data->file);
+ }
+
+ return FALSE;
+}
+
+void
+tracker_file_system_delete_files (TrackerFileSystem *file_system,
+ GFile *root,
+ GFileType file_type)
+{
+ DeleteFilesData data = { file_system, NULL, file_type };
+ GNode *node;
+
+ g_return_if_fail (TRACKER_IS_FILE_SYSTEM (file_system));
+ g_return_if_fail (G_IS_FILE (root));
+
+ node = file_system_get_node (file_system, root);
+ g_return_if_fail (node != NULL);
+
+ /* We need to get the files to delete into a list, so
+ * the node tree isn't modified during traversal.
+ */
+ g_node_traverse (node,
+ G_PRE_ORDER,
+ (file_type == G_FILE_TYPE_REGULAR) ?
+ G_TRAVERSE_LEAVES : G_TRAVERSE_ALL,
+ -1, append_deleted_files,
+ &data);
+
+ g_list_foreach (data.list, (GFunc) g_object_unref, NULL);
+ g_list_free (data.list);
+}
diff --git a/src/libtracker-miner/tracker-file-system.h b/src/libtracker-miner/tracker-file-system.h
index a8b064a..575ccb5 100644
--- a/src/libtracker-miner/tracker-file-system.h
+++ b/src/libtracker-miner/tracker-file-system.h
@@ -71,6 +71,10 @@ void tracker_file_system_traverse (TrackerFileSystem
TrackerFileSystemTraverseFunc func,
gpointer user_data);
+void tracker_file_system_delete_files (TrackerFileSystem *file_system,
+ GFile *root,
+ GFileType file_type);
+
/* properties */
void tracker_file_system_register_property (GQuark prop,
GDestroyNotify destroy_notify);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]