[tracker/rss-enclosures] libtracker-miner: Only re-check directories affected by the new mount point



commit 9cd14929c5a26dbe3115b8e6fe9b1c54b88f9c10
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu Jun 10 17:16:44 2010 +0200

    libtracker-miner: Only re-check directories affected by the new mount point

 src/libtracker-miner/tracker-miner-fs.c |   32 +++++++++--
 src/miners/fs/tracker-miner-files.c     |   91 +++++++++++++++----------------
 2 files changed, 69 insertions(+), 54 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index fda6b04..1dd38dc 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -3039,6 +3039,16 @@ should_recurse_for_directory (TrackerMinerFS *fs,
 	return recurse;
 }
 
+
+static gint
+directory_compare_cb (gconstpointer a,
+                      gconstpointer b)
+{
+	return !g_file_equal (((DirectoryData *)a)->file,
+	                      ((DirectoryData *)b)->file);
+}
+
+
 /* This function is for internal use, adds the file to the processing
  * queue with the same directory settings than the corresponding
  * config directory.
@@ -3079,12 +3089,22 @@ tracker_miner_fs_directory_add (TrackerMinerFS *fs,
 
 	dir_data = directory_data_new (file, recurse);
 
-	fs->private->config_directories =
-		g_list_append (fs->private->config_directories, dir_data);
-
-	fs->private->directories =
-		g_list_append (fs->private->directories,
-			       directory_data_ref (dir_data));
+	/* New directory to add in config_directories? */
+	if (!g_list_find_custom (fs->private->config_directories,
+	                         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,
+			               directory_data_ref (dir_data));
+	} else {
+		/* Existing directory in config_directories,
+		 * just force re-check */
+		fs->private->directories =
+			g_list_append (fs->private->directories,
+			               dir_data);
+	}
 
 	crawl_directories_start (fs);
 }
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index ec6453c..2a0e504 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -177,9 +177,6 @@ static void        miner_finished_cb                    (TrackerMinerFS *fs,
                                                          guint           total_files_ignored,
                                                          gpointer        user_data);
 
-static gboolean    miner_files_path_is_root_for_indexed_directories (TrackerMinerFiles *miner,
-                                                                     const gchar *root_path);
-
 G_DEFINE_TYPE (TrackerMinerFiles, tracker_miner_files, TRACKER_TYPE_MINER_FS)
 
 static void
@@ -860,22 +857,50 @@ mount_point_added_cb (TrackerStorage *storage,
 		g_message ("  Not crawling, removable devices disabled in config");
 	} else if (optical && !tracker_config_get_index_optical_discs (priv->config)) {
 		g_message ("  Not crawling, optical devices discs disabled in config");
-	} else if (!removable && !optical) {
-		/* We should only add idles to re-check the monitored locations
-		 *  AFTER first whole index is finished (and only if the mount
-		 *  point contains one of the configured locations to monitor) */
-		if (miner->private->first_index_run &&
-		    miner_files_path_is_root_for_indexed_directories (miner,
-		                                                      mount_point)) {
-			g_message ("  Non-removable mount, adding recheck idle");
-			if (miner->private->force_recheck_id == 0) {
-				/* Set idle to recheck if not already there */
-				miner->private->force_recheck_id =
-					g_idle_add (miner_files_force_recheck_idle, miner);
+	} else if (!removable &&
+	           !optical &&
+	           miner->private->first_index_run) {
+			GSList *it;
+
+			/* 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;
+
+					file = g_file_new_for_path (it->data);
+					uri = g_file_get_uri (file);
+					g_message ("  Re-check of path '%s' needed", uri);
+					tracker_miner_fs_directory_add (TRACKER_MINER_FS (user_data),
+					                                file,
+					                                TRUE);
+					g_object_unref (file);
+					g_free (uri);
+				}
+			}
+
+			/* Check if one of the non-recursively indexed locations is in
+			 *  the mount path... */
+			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);
+					tracker_miner_fs_directory_add (TRACKER_MINER_FS (user_data),
+					                                file,
+					                                FALSE);
+					g_object_unref (file);
+					g_free (uri);
+				}
 			}
-		} else {
-			g_message ("  Not crawling by default non-removable mount");
-		}
 	} else {
 		g_message ("  Adding directory to crawler's queue");
 
@@ -2051,33 +2076,3 @@ tracker_miner_files_monitor_directory (GFile    *file,
          */
 	return TRUE;
 }
-
-
-/* Returns TRUE if one of the directories set to be indexed is actually
- *  located inside the given root path. */
-static gboolean
-miner_files_path_is_root_for_indexed_directories (TrackerMinerFiles *miner,
-                                                  const gchar *root_path)
-{
-	GSList *it;
-
-	/* Check if one of the recursively indexed ones... */
-	for (it = tracker_config_get_index_recursive_directories (miner->private->config);
-	     it;
-	     it= g_slist_next (it)) {
-		if (g_str_has_prefix (it->data, root_path)) {
-			return TRUE;
-		}
-	}
-
-	/* Check if one of the non-recursively indexed ones... */
-	for (it = tracker_config_get_index_single_directories (miner->private->config);
-	     it;
-	     it= g_slist_next (it)) {
-		if (g_str_has_prefix (it->data, root_path)) {
-			return TRUE;
-		}
-	}
-
-	return FALSE;
-}



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