[tracker/miner-fs-dbus-api: 2/13] Make tracker_miner_fs_file_add() take a check_parents arg.



commit ffc36f0c068a4b9f2d15e651ce2ad3b42d1347de
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Aug 19 14:55:46 2010 +0200

    Make tracker_miner_fs_file_add() take a check_parents arg.

 src/libtracker-miner/tracker-miner-fs.c   |   63 ++++++++++++++++++++++++++++-
 src/libtracker-miner/tracker-miner-fs.h   |    3 +-
 src/miners/fs/tracker-main.c              |    2 +-
 src/miners/fs/tracker-miner-files-index.c |    2 +-
 4 files changed, 66 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 395e810..bfe7023 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1218,6 +1218,30 @@ file_is_crawl_directory (TrackerMinerFS *fs,
 	return FALSE;
 }
 
+static DirectoryData *
+find_config_directory (TrackerMinerFS *fs,
+                       GFile          *file)
+{
+	GList *dirs;
+
+	dirs = fs->private->config_directories;
+
+	while (dirs) {
+		DirectoryData *data;
+
+		data = dirs->data;
+		dirs = dirs->next;
+
+		if (g_file_equal (data->file, file) ||
+		    (data->recurse && (g_file_has_prefix (file, data->file)))) {
+			return data;
+		}
+	}
+
+	return NULL;
+}
+
+
 static void
 ensure_iri_cache (TrackerMinerFS *fs,
                   GFile          *file)
@@ -3571,7 +3595,8 @@ tracker_miner_fs_directory_remove_full (TrackerMinerFS *fs,
  **/
 void
 tracker_miner_fs_file_add (TrackerMinerFS *fs,
-                           GFile          *file)
+                           GFile          *file,
+                           gboolean        check_parents)
 {
 	gboolean should_process;
 	gchar *path;
@@ -3588,6 +3613,42 @@ tracker_miner_fs_file_add (TrackerMinerFS *fs,
 	         path);
 
 	if (should_process) {
+		if (check_parents) {
+			DirectoryData *data;
+			GFile *parent;
+			GList *parents = NULL, *p;
+
+			parent = g_file_get_parent (file);
+
+			if (!parent) {
+				return;
+			}
+
+			data = find_config_directory (fs, parent);
+
+			if (!data) {
+				return;
+			}
+
+			/* Add parent directories until we're past the config dir */
+			while (parent &&
+			       !g_file_has_prefix (data->file, parent)) {
+				parents = g_list_prepend (parents, parent);
+				parent = g_file_get_parent (parent);
+			}
+
+			/* Last parent fetched is not added to the list */
+			if (parent) {
+				g_object_unref (parent);
+			}
+
+			for (p = parents; p; p = p->next) {
+				g_queue_push_tail (fs->private->items_updated, p->data);
+			}
+
+			g_list_free (parents);
+		}
+
 		g_queue_push_tail (fs->private->items_updated,
 		                   g_object_ref (file));
 
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 2188d63..a959809 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -103,7 +103,8 @@ gboolean              tracker_miner_fs_directory_remove     (TrackerMinerFS *fs,
 gboolean              tracker_miner_fs_directory_remove_full (TrackerMinerFS *fs,
                                                               GFile          *file);
 void                  tracker_miner_fs_file_add             (TrackerMinerFS *fs,
-                                                             GFile          *file);
+                                                             GFile          *file,
+                                                             gboolean        check_parents);
 void                  tracker_miner_fs_file_notify          (TrackerMinerFS *fs,
                                                              GFile          *file,
                                                              const GError   *error);
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 1d08403..676faad 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -636,7 +636,7 @@ main (gint argc, gchar *argv[])
 		file = g_file_new_for_commandline_arg (add_file);
 		miner_files = tracker_miner_files_new (NULL);
 
-		tracker_miner_fs_file_add (TRACKER_MINER_FS (miner_files), file);
+		tracker_miner_fs_file_add (TRACKER_MINER_FS (miner_files), file, FALSE);
 		g_object_unref (file);
 	}
 
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index b725c0f..003c171 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -184,7 +184,7 @@ mime_types_cb (GObject      *object,
 
                         url = tracker_sparql_cursor_get_string (cursor, 0, NULL);
                         file = g_file_new_for_uri (url);
-                        tracker_miner_fs_file_add (TRACKER_MINER_FS (mtd->miner_files), file);
+                        tracker_miner_fs_file_add (TRACKER_MINER_FS (mtd->miner_files), file, FALSE);
                         g_object_unref (file);
 		}
 



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