[tracker/mounts-without-volumes: 13/23] libtracker-miner: Support crawl directories with NULL parent



commit 45a26266dfbccfae4920633bfdf70fe41e645b67
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Mon Jun 14 09:48:54 2010 +0200

    libtracker-miner: Support crawl directories with NULL parent

 src/libtracker-miner/tracker-miner-fs.c |   75 ++++++++++++++++++++-----------
 1 files changed, 48 insertions(+), 27 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 3e8086a..4e13862 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1028,17 +1028,24 @@ sparql_update_cb (GObject      *object,
 		if (fs->private->current_parent) {
 			GFile *parent;
 
+			/* Note: parent may be NULL if the file represents
+			 *  the root directory of the file system (applies to
+			 *  .gvfs mounts also!) */
 			parent = g_file_get_parent (data->file);
 
-			if (g_file_equal (parent, fs->private->current_parent) &&
-			    g_hash_table_lookup (fs->private->iri_cache, data->file) == NULL) {
-				/* Item is processed, add an empty element for the processed GFile,
-				 * in case it is again processed before the cache expires
-				 */
-				g_hash_table_insert (fs->private->iri_cache, g_object_ref (data->file), NULL);
+			if(parent) {
+				if (g_file_equal (parent, fs->private->current_parent) &&
+				    g_hash_table_lookup (fs->private->iri_cache, data->file) == NULL) {
+					/* Item is processed, add an empty element for the processed GFile,
+					 * in case it is again processed before the cache expires
+					 */
+					g_hash_table_insert (fs->private->iri_cache,
+					                     g_object_ref (data->file),
+					                     NULL);
+				}
+
+				g_object_unref (parent);
 			}
-
-			g_object_unref (parent);
 		}
 	}
 
@@ -1204,7 +1211,15 @@ ensure_iri_cache (TrackerMinerFS *fs,
 
 	g_hash_table_remove_all (fs->private->iri_cache);
 
+	/* Note: parent may be NULL if the file represents
+	 *  the root directory of the file system (applies to
+	 *  .gvfs mounts also!) */
 	parent = g_file_get_parent (file);
+
+	if (!parent) {
+		return;
+	}
+
 	uri = g_file_get_uri (parent);
 
 	g_debug ("Generating IRI cache for folder: %s", uri);
@@ -2312,10 +2327,14 @@ ensure_mtime_cache (TrackerMinerFS *fs,
 		                                                  (GDestroyNotify) g_free);
 	}
 
+	/* Note: parent may be NULL if the file represents
+	 *  the root directory of the file system (applies to
+	 *  .gvfs mounts also!) */
 	parent = g_file_get_parent (file);
 
 	if (fs->private->current_parent) {
-		if (g_file_equal (parent, fs->private->current_parent)) {
+		if (parent &&
+		    g_file_equal (parent, fs->private->current_parent)) {
 			/* Cache is still valid */
 			g_object_unref (parent);
 			return;
@@ -2328,30 +2347,33 @@ ensure_mtime_cache (TrackerMinerFS *fs,
 
 	g_hash_table_remove_all (fs->private->mtime_cache);
 
-	uri = g_file_get_uri (parent);
+	/* Initialize data contents */
+	data.main_loop = g_main_loop_new (NULL, FALSE);
+	data.values = g_hash_table_ref (fs->private->mtime_cache);
 
-	g_debug ("Generating mtime cache for folder: %s", uri);
+	if (parent) {
+		uri = g_file_get_uri (parent);
 
-	query = g_strdup_printf ("SELECT ?url ?last { ?u nfo:belongsToContainer ?p ; "
-	                                                "nie:url ?url ; "
-	                                                "nfo:fileLastModified ?last . "
-	                                             "?p nie:url \"%s\" }", uri);
+		g_debug ("Generating mtime cache for folder: %s", uri);
 
-	g_free (uri);
+		query = g_strdup_printf ("SELECT ?url ?last { ?u nfo:belongsToContainer ?p ; "
+		                                                "nie:url ?url ; "
+		                                                "nfo:fileLastModified ?last . "
+		                                             "?p nie:url \"%s\" }", uri);
 
-	data.main_loop = g_main_loop_new (NULL, FALSE);
-	data.values = g_hash_table_ref (fs->private->mtime_cache);
+		g_free (uri);
 
-	tracker_miner_execute_sparql (TRACKER_MINER (fs),
-	                              query,
-	                              NULL,
-	                              cache_query_cb,
-	                              &data);
-	g_free (query);
+		tracker_miner_execute_sparql (TRACKER_MINER (fs),
+		                              query,
+		                              NULL,
+		                              cache_query_cb,
+		                              &data);
+		g_free (query);
 
-	g_main_loop_run (data.main_loop);
+		g_main_loop_run (data.main_loop);
+	}
 
-	if (g_hash_table_size (data.values) == 0 &&
+	if ((!parent || g_hash_table_size (data.values) == 0 ) &&
 	    file_is_crawl_directory (fs, file)) {
 		/* File is a crawl directory itself, query its mtime directly */
 		uri = g_file_get_uri (file);
@@ -2379,7 +2401,6 @@ ensure_mtime_cache (TrackerMinerFS *fs,
 	g_main_loop_unref (data.main_loop);
 	g_hash_table_unref (data.values);
 
-
 	/* Iterate repopulated HT and add all to the check_removed HT */
 	g_hash_table_foreach (fs->private->mtime_cache,
 	                      add_to_check_removed_cb,



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