[tracker/mounts-without-volumes: 11/23] libtracker-miner: Consider mounts inside recursively indexed locations



commit 645c41359c277fe4f4178f91b061e6f820485394
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu Jun 10 18:35:29 2010 +0200

    libtracker-miner: Consider mounts inside recursively indexed locations
    
    * Also, don't add a location to re-check if already there or if a parent
    location to be recursively indexed is also there.

 src/libtracker-miner/tracker-miner-fs.c |   44 ++++++++++++++++-------
 src/miners/fs/tracker-miner-files.c     |   58 +++++++++++++++++++++----------
 2 files changed, 70 insertions(+), 32 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 1dd38dc..59cc5ce 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -3040,12 +3040,19 @@ should_recurse_for_directory (TrackerMinerFS *fs,
 }
 
 
+/* Returns 0 if 'a' and 'b' point to the same diretory, OR if
+ *  'b' is contained inside directory 'a' and 'a' is recursively
+ *  indexed. */
 static gint
 directory_compare_cb (gconstpointer a,
                       gconstpointer b)
 {
-	return !g_file_equal (((DirectoryData *)a)->file,
-	                      ((DirectoryData *)b)->file);
+	DirectoryData *dda = (DirectoryData *)a;
+	DirectoryData *ddb = (DirectoryData *)b;
+
+	return (g_file_equal (dda->file, ddb->file) ||
+	        (dda->recurse &&
+	         g_file_has_prefix (ddb->file, dda->file))) ? 0 : -1;
 }
 
 
@@ -3063,10 +3070,18 @@ tracker_miner_fs_directory_add_internal (TrackerMinerFS *fs,
 	recurse = should_recurse_for_directory (fs, file);
 	data = directory_data_new (file, recurse);
 
-	fs->private->directories =
-		g_list_append (fs->private->directories, data);
+	/* Only add if not already there */
+	if (!g_list_find_custom (fs->private->directories,
+	                         data,
+	                         directory_compare_cb)) {
+		fs->private->directories =
+			g_list_append (fs->private->directories,
+			               directory_data_ref (data));
 
-	crawl_directories_start (fs);
+		crawl_directories_start (fs);
+	}
+
+	directory_data_unref (data);
 }
 
 /**
@@ -3094,19 +3109,22 @@ tracker_miner_fs_directory_add (TrackerMinerFS *fs,
 	                         dir_data,
 	                         directory_compare_cb)) {
 		fs->private->config_directories =
-			g_list_append (fs->private->config_directories, dir_data);
-		fs->private->directories =
-			g_list_append (fs->private->directories,
+			g_list_append (fs->private->config_directories,
 			               directory_data_ref (dir_data));
-	} else {
-		/* Existing directory in config_directories,
-		 * just force re-check */
+	}
+
+	/* If not already in the list to process, add it */
+	if (!g_list_find_custom (fs->private->directories,
+	                         dir_data,
+	                         directory_compare_cb)) {
 		fs->private->directories =
 			g_list_append (fs->private->directories,
-			               dir_data);
+			               directory_data_ref (dir_data));
+
+		crawl_directories_start (fs);
 	}
 
-	crawl_directories_start (fs);
+	directory_data_unref (dir_data);
 }
 
 static void
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 5ef7ddc..5dba40c 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -841,7 +841,6 @@ mount_point_added_cb (TrackerStorage *storage,
 {
 	TrackerMinerFiles *miner = user_data;
 	TrackerMinerFilesPrivate *priv;
-	GFile *file;
 	gchar *urn;
 	gboolean index_removable_devices;
 	gboolean index_optical_discs;
@@ -860,27 +859,43 @@ mount_point_added_cb (TrackerStorage *storage,
 	} else if (!removable &&
 	           !optical &&
 	           miner->private->first_index_run) {
+		GFile *mount_point_file;
 		GSList *it;
 
+		mount_point_file = g_file_new_for_path (mount_point);
+
 		/* Check if one of the recursively indexed locations is in
 		 *   the mounted path, or if the mounted path is inside
 		 *   a recursively indexed directory... */
 		for (it = tracker_config_get_index_recursive_directories (miner->private->config);
 		     it;
 		     it= g_slist_next (it)) {
-			if (g_str_has_prefix (it->data, mount_point) ||
-			    g_str_has_prefix (mount_point, it->data)) {
-				gchar *uri;
+			GFile *config_file;
+
+			config_file = g_file_new_for_path (it->data);
 
-				file = g_file_new_for_path (it->data);
-				uri = g_file_get_uri (file);
-				g_message ("  Re-check of path '%s' needed", uri);
+			if (g_file_equal (config_file, mount_point_file) ||
+			    g_file_has_prefix (config_file, mount_point_file)) {
+				/* If the config path is contained inside the mount path,
+				 *  then add the config path to re-check */
+				g_message ("  Re-check of configured path '%s' "
+				           "needed (recursively)",
+				           (gchar *)it->data);
+				tracker_miner_fs_directory_add (TRACKER_MINER_FS (user_data),
+				                                config_file,
+				                                TRUE);
+			} else if (g_file_has_prefix (mount_point_file, config_file)) {
+				/* If the mount path is contained inside the config path,
+				 *  then add the mount path to re-check */
+				g_message ("  Re-check of path '%s' needed (inside configured"
+				           " path '%s')",
+				           mount_point,
+				           (gchar *)it->data);
 				tracker_miner_fs_directory_add (TRACKER_MINER_FS (user_data),
-				                                file,
+				                                mount_point_file,
 				                                TRUE);
-				g_object_unref (file);
-				g_free (uri);
 			}
+			g_object_unref (config_file);
 		}
 
 		/* Check if one of the non-recursively indexed locations is in
@@ -888,20 +903,25 @@ mount_point_added_cb (TrackerStorage *storage,
 		for (it = tracker_config_get_index_single_directories (miner->private->config);
 		     it;
 		     it= g_slist_next (it)) {
-			if (g_str_has_prefix (it->data, mount_point)) {
-				gchar *uri;
-
-				file = g_file_new_for_path (it->data);
-				uri = g_file_get_uri (file);
-				g_message ("  Re-check of path '%s' needed", uri);
+			GFile *config_file;
+
+			config_file = g_file_new_for_path (it->data);
+			if (g_file_equal (config_file, mount_point_file) ||
+			    g_file_has_prefix (config_file, mount_point_file)) {
+				g_message ("  Re-check of configured path '%s' "
+				           "needed (non-recursively)",
+				           (gchar *)it->data);
 				tracker_miner_fs_directory_add (TRACKER_MINER_FS (user_data),
-				                                file,
+				                                config_file,
 				                                FALSE);
-				g_object_unref (file);
-				g_free (uri);
 			}
+			g_object_unref (config_file);
 		}
+
+		g_object_unref (mount_point_file);
 	} else {
+		GFile *file;
+
 		g_message ("  Adding directory to crawler's queue");
 
 		file = g_file_new_for_path (mount_point);



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