tracker r1920 - in branches/indexer-split: . src/libtracker-common src/trackerd



Author: mr
Date: Wed Jul 23 17:59:31 2008
New Revision: 1920
URL: http://svn.gnome.org/viewvc/tracker?rev=1920&view=rev

Log:
	* src/libtracker-common/tracker-config.c: Don't leak from calling
	tracker_path_list_filter_duplicates(). 

	* src/trackerd/tracker-processor.c: Implemented the old config
	option WatchDirectoryRoots and CrawlDirectoryRoots.


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/libtracker-common/tracker-config.c
   branches/indexer-split/src/trackerd/tracker-crawler.c
   branches/indexer-split/src/trackerd/tracker-crawler.h
   branches/indexer-split/src/trackerd/tracker-monitor.c
   branches/indexer-split/src/trackerd/tracker-monitor.h
   branches/indexer-split/src/trackerd/tracker-processor.c

Modified: branches/indexer-split/src/libtracker-common/tracker-config.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-config.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-config.c	Wed Jul 23 17:59:31 2008
@@ -1046,6 +1046,7 @@
 			 const gchar   *key)
 {
 	TrackerConfigPriv  *priv;
+	GSList             *l;
 	gchar		  **value;
 
 	priv = GET_PRIV (config);
@@ -1054,26 +1055,29 @@
 
 	if (strcmp (property, "watch-directory-roots") == 0) {
 		if (value) {
-			priv->watch_directory_roots =
+			priv->watch_directory_roots = l = 
 				config_string_list_to_gslist ((const gchar **) value, TRUE);
 			priv->watch_directory_roots = 
 				tracker_path_list_filter_duplicates (priv->watch_directory_roots);
+			g_slist_free (l);
 		}
 	}
 	else if (strcmp (property, "crawl-directory-roots") == 0) {
 		if (value) {
-			priv->crawl_directory_roots =
+			priv->crawl_directory_roots = l =
 				config_string_list_to_gslist ((const gchar **) value, TRUE);
 			priv->crawl_directory_roots = 
 				tracker_path_list_filter_duplicates (priv->crawl_directory_roots);
+			g_slist_free (l);
 		}
 	}
 	else if (strcmp (property, "no-watch-directory-roots") == 0) {
 		if (value) {
-			priv->no_watch_directory_roots =
+			priv->no_watch_directory_roots = l = 
 				config_string_list_to_gslist ((const gchar **) value, TRUE);
 			priv->no_watch_directory_roots = 
 				tracker_path_list_filter_duplicates (priv->no_watch_directory_roots);
+			g_slist_free (l);
 		}
 	}
 	else if (strcmp (property, "no-index-file-types") == 0) {
@@ -1998,9 +2002,10 @@
 tracker_config_add_watch_directory_roots (TrackerConfig *config,
 					  gchar * const *roots)
 {
-	TrackerConfigPriv  *priv;
-	gchar		   *validated_root;
-	gchar * const	   *p;
+	TrackerConfigPriv *priv;
+	GSList            *l;
+	gchar		  *validated_root;
+	gchar * const	  *p;
 
 	g_return_if_fail (TRACKER_IS_CONFIG (config));
 	g_return_if_fail (roots != NULL);
@@ -2019,9 +2024,11 @@
 							      validated_root);
 	}
 
-	priv->watch_directory_roots = 
+	l = priv->watch_directory_roots;
+	priv->watch_directory_roots =
 		tracker_path_list_filter_duplicates (priv->watch_directory_roots);
-
+	g_slist_free (l);
+       		
 	g_object_notify (G_OBJECT (config), "watch-directory-roots");
 }
 
@@ -2029,9 +2036,10 @@
 tracker_config_add_crawl_directory_roots (TrackerConfig *config,
 					  gchar * const *roots)
 {
-	TrackerConfigPriv  *priv;
-	gchar		   *validated_root;
-	gchar * const	   *p;
+	TrackerConfigPriv *priv;
+	GSList            *l;
+	gchar		  *validated_root;
+	gchar * const	  *p;
 
 	g_return_if_fail (TRACKER_IS_CONFIG (config));
 	g_return_if_fail (roots != NULL);
@@ -2050,8 +2058,10 @@
 							      validated_root);
 	}
 
-	priv->crawl_directory_roots = 
+	l = priv->crawl_directory_roots;
+	priv->crawl_directory_roots =
 		tracker_path_list_filter_duplicates (priv->crawl_directory_roots);
+	g_slist_free (l);
 
 	g_object_notify (G_OBJECT (config), "crawl-directory-roots");
 }
@@ -2060,9 +2070,10 @@
 tracker_config_add_no_watch_directory_roots (TrackerConfig *config,
 					     gchar * const *roots)
 {
-	TrackerConfigPriv  *priv;
-	gchar		   *validated_root;
-	gchar * const	   *p;
+	TrackerConfigPriv *priv;
+	GSList            *l;
+	gchar             *validated_root;
+	gchar * const	  *p;
 
 	g_return_if_fail (TRACKER_IS_CONFIG (config));
 	g_return_if_fail (roots != NULL);
@@ -2081,8 +2092,10 @@
 								 validated_root);
 	}
 
+	l = priv->no_watch_directory_roots;
 	priv->no_watch_directory_roots = 
 		tracker_path_list_filter_duplicates (priv->no_watch_directory_roots);
+	g_slist_free (l);
 
 	g_object_notify (G_OBJECT (config), "no-watch-directory-roots");
 }

Modified: branches/indexer-split/src/trackerd/tracker-crawler.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-crawler.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-crawler.c	Wed Jul 23 17:59:31 2008
@@ -66,7 +66,6 @@
 	GSList         *current_recurse_path;
 	gboolean        handled_recurse_paths;
 
-	/* Specific to each crawl ... */
 	GList          *ignored_directory_patterns;
 	GList          *ignored_file_patterns;
 	GList          *index_file_patterns;
@@ -546,48 +545,58 @@
 
 	/* Process next path in list */
 	if (!priv->handled_paths) {
+		/* This is done so we don't go over the list again
+		 * when we get to the end and the current item = NULL.
+		 */
 		priv->handled_paths = TRUE;
 
 		if (!priv->current_path) {
 			priv->current_path = priv->paths;
-		} else {
-			priv->current_path = priv->current_path->next;
 		}
-		
+	} else {
 		if (priv->current_path) {
-			g_message ("  Searching directory:'%s'", 
-				   (gchar*) priv->current_path->data);
-			
-			file = g_file_new_for_path (priv->current_path->data);
-			add_directory (crawler, file);
-			g_object_unref (file);
-			
-			return TRUE;
+			priv->current_path = priv->current_path->next;
 		}
 	}
 
+	if (priv->current_path) {
+		g_message ("  Searching directory:'%s'", 
+			   (gchar*) priv->current_path->data);
+		
+		file = g_file_new_for_path (priv->current_path->data);
+		add_directory (crawler, file);
+		g_object_unref (file);
+		
+		return TRUE;
+	}
+
 	/* Process next recursive path in list */
 	if (!priv->handled_recurse_paths) {
+		/* This is done so we don't go over the list again
+		 * when we get to the end and the current item = NULL.
+		 */
 		priv->handled_recurse_paths = TRUE;
 
 		if (!priv->current_recurse_path) {
 			priv->current_recurse_path = priv->recurse_paths;
-		} else {
-			priv->current_recurse_path = priv->current_recurse_path->next;
 		}
-	
+	} else {
 		if (priv->current_recurse_path) {
-			g_message ("  Searching directory:'%s' (recursively)", 
-				   (gchar *) priv->current_recurse_path->data);
-			
-			file = g_file_new_for_path (priv->current_recurse_path->data);
-			add_directory (crawler, file);
-			g_object_unref (file);
-			
-			return TRUE;
+			priv->current_recurse_path = priv->current_recurse_path->next;
 		}
 	}
 
+	if (priv->current_recurse_path) {
+		g_message ("  Searching directory:'%s' (recursively)", 
+			   (gchar *) priv->current_recurse_path->data);
+		
+		file = g_file_new_for_path (priv->current_recurse_path->data);
+		add_directory (crawler, file);
+		g_object_unref (file);
+		
+		return TRUE;
+	}
+
 	priv->idle_id = 0;
 	priv->finished = TRUE;
 
@@ -754,6 +763,7 @@
 	GList                 *recurse_directories;
 	GList                 *directories;
 	GList                 *l;
+	GSList                *sl;
 	gchar                 *path;
 	gboolean               exists;
 
@@ -769,66 +779,70 @@
 	directories =
 		tracker_module_config_get_monitor_directories (priv->module_name);
 
-	if (!recurse_directories && !directories) {
-		g_message ("  No directories to iterate, doing nothing");
-		return TRUE;
-	}
-
-	/* First we do non-recursive directories */
-	for (l = directories; l; l = l->next) {
-		path = l->data;
-
-		/* Check location exists before we do anything */
-		file = g_file_new_for_path (path);
-		exists = g_file_query_exists (file, NULL);
-
-		if (!exists) {
-			g_message ("  Directory:'%s' does not exist",
+	if (recurse_directories || directories) {
+		/* First we do non-recursive directories */
+		for (l = directories; l; l = l->next) {
+			path = l->data;
+			
+			/* Check location exists before we do anything */
+			file = g_file_new_for_path (path);
+			exists = g_file_query_exists (file, NULL);
+			
+			if (!exists) {
+				g_message ("  Directory:'%s' does not exist",
+					   path);
+				g_object_unref (file);
+				continue;
+			}
+			
+			g_message ("  Directory:'%s' added to list to crawl",
 				   path);
+			
+			priv->paths = g_slist_append (priv->paths, g_strdup (l->data));
 			g_object_unref (file);
-			continue;
 		}
-
-		g_message ("  Directory:'%s' added to list to crawl",
-			   path);
-
-		priv->paths = g_slist_prepend (priv->paths, g_strdup (l->data));
-		g_object_unref (file);
-	}
-
-	g_list_free (directories);
-
-	/* Second we do recursive directories */
-	for (l = recurse_directories; l; l = l->next) {
-		path = l->data;
-
-		/* Check location exists before we do anything */
-		file = g_file_new_for_path (path);
-		exists = g_file_query_exists (file, NULL);
-
-		if (!exists) {
-			g_message ("  Directory:'%s' does not exist",
+		
+		g_list_free (directories);
+		
+		/* Second we do recursive directories */
+		for (l = recurse_directories; l; l = l->next) {
+			path = l->data;
+			
+			/* Check location exists before we do anything */
+			file = g_file_new_for_path (path);
+			exists = g_file_query_exists (file, NULL);
+			
+			if (!exists) {
+				g_message ("  Directory:'%s' does not exist",
+					   path);
+				g_object_unref (file);
+				continue;
+			}
+			
+			g_message ("  Directory:'%s' added to list to crawl (recursively)",
 				   path);
+			
+			priv->recurse_paths = g_slist_append (priv->recurse_paths, g_strdup (l->data));
 			g_object_unref (file);
-			continue;
 		}
-
-		g_message ("  Directory:'%s' added to list to crawl (recursively)",
-			   path);
-
-		priv->recurse_paths = g_slist_prepend (priv->recurse_paths, g_strdup (l->data));
-		g_object_unref (file);
+		
+		g_list_free (recurse_directories);
+	} else {
+		g_message ("  No directories from module config");
 	}
 
-	g_list_free (recurse_directories);
-
 	if (!priv->paths && !priv->recurse_paths) {
 		g_message ("  No directories that actually exist to iterate, doing nothing");
 		return FALSE;
 	}
-
-	priv->paths = g_slist_reverse (priv->paths);
-	priv->recurse_paths = g_slist_reverse (priv->recurse_paths);
+	
+	sl = priv->paths;
+	priv->paths = tracker_path_list_filter_duplicates (priv->paths);
+	g_slist_free (sl);
+
+	sl = priv->recurse_paths;
+	priv->recurse_paths = tracker_path_list_filter_duplicates (priv->recurse_paths);
+	g_slist_free (sl);
 
 	/* Time the event */
 	if (priv->timer) {
@@ -890,3 +904,23 @@
 		       priv->files_found,
 		       priv->files_ignored);
 }
+
+/* This is a convenience function to add extra locations because
+ * sometimes we want to add locations like the MMC or others to the
+ * "Files" module, for example.
+ */
+void
+tracker_crawler_add (TrackerCrawler *crawler,
+		     const gchar    *path)
+{
+	TrackerCrawlerPrivate *priv;
+
+	g_return_if_fail (TRACKER_IS_CRAWLER (crawler));
+	g_return_if_fail (path != NULL);
+
+	priv = crawler->private;
+
+	g_return_if_fail (priv->running == FALSE);
+
+	priv->recurse_paths = g_slist_append (priv->recurse_paths, g_strdup (path));
+}

Modified: branches/indexer-split/src/trackerd/tracker-crawler.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-crawler.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-crawler.h	Wed Jul 23 17:59:31 2008
@@ -55,6 +55,10 @@
 gboolean        tracker_crawler_start    (TrackerCrawler *crawler);
 void            tracker_crawler_stop     (TrackerCrawler *crawler);
 
+/* Convenience API for old .cfg file */
+void            tracker_crawler_add      (TrackerCrawler *crawler,
+					  const gchar    *path);
+
 G_END_DECLS
 
 #endif /* __TRACKERD_CRAWLER_H__ */

Modified: branches/indexer-split/src/trackerd/tracker-monitor.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-monitor.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-monitor.c	Wed Jul 23 17:59:31 2008
@@ -405,8 +405,8 @@
 
 gboolean
 tracker_monitor_add (TrackerMonitor *monitor,
-		     GFile          *file,
-		     const gchar    *module_name)
+		     const gchar    *module_name,
+		     GFile          *file)
 {
 	TrackerMonitorPrivate *priv;
 	GFileMonitor          *file_monitor;
@@ -417,8 +417,8 @@
 	gchar                 *path;
 
 	g_return_val_if_fail (TRACKER_IS_MONITOR (monitor), FALSE);
-	g_return_val_if_fail (G_IS_FILE (file), FALSE);
 	g_return_val_if_fail (module_name != NULL, FALSE);
+	g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
 	priv = TRACKER_MONITOR_GET_PRIVATE (monitor);
 	
@@ -504,8 +504,8 @@
 
 gboolean
 tracker_monitor_remove (TrackerMonitor *monitor,
-			GFile          *file,
-			const gchar    *module_name)
+			const gchar    *module_name,
+			GFile          *file)
 {
 	TrackerMonitorPrivate *priv;
 	GFileMonitor          *file_monitor;
@@ -513,8 +513,8 @@
 	gchar                 *path;
 
 	g_return_val_if_fail (TRACKER_IS_MONITOR (monitor), FALSE);
-	g_return_val_if_fail (G_IS_FILE (file), FALSE);
 	g_return_val_if_fail (module_name != NULL, FALSE);
+	g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
 	priv = TRACKER_MONITOR_GET_PRIVATE (monitor);
 
@@ -553,15 +553,15 @@
 
 gboolean
 tracker_monitor_is_watched (TrackerMonitor *monitor,
-			    GFile          *file,
-			    const gchar    *module_name)
+			    const gchar    *module_name,
+			    GFile          *file)
 {
 	TrackerMonitorPrivate *priv;
 	GHashTable            *monitors;
 
 	g_return_val_if_fail (TRACKER_IS_MONITOR (monitor), FALSE);
-	g_return_val_if_fail (G_IS_FILE (file), FALSE);
 	g_return_val_if_fail (module_name != NULL, FALSE);
+	g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
 	priv = TRACKER_MONITOR_GET_PRIVATE (monitor);
 
@@ -577,8 +577,8 @@
 
 gboolean
 tracker_monitor_is_watched_by_string (TrackerMonitor *monitor,
-				      const gchar    *path,
-				      const gchar    *module_name)
+				      const gchar    *module_name,
+				      const gchar    *path)
 {
 	TrackerMonitorPrivate *priv;
 	GFile                 *file;
@@ -586,8 +586,8 @@
 	gboolean               watched;
 
 	g_return_val_if_fail (TRACKER_IS_MONITOR (monitor), FALSE);
-	g_return_val_if_fail (path != NULL, FALSE);
 	g_return_val_if_fail (module_name != NULL, FALSE);
+	g_return_val_if_fail (path != NULL, FALSE);
 
 	priv = TRACKER_MONITOR_GET_PRIVATE (monitor);
 

Modified: branches/indexer-split/src/trackerd/tracker-monitor.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-monitor.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-monitor.h	Wed Jul 23 17:59:31 2008
@@ -52,17 +52,17 @@
 GType           tracker_monitor_get_type             (void);
 TrackerMonitor *tracker_monitor_new                  (TrackerConfig  *config);
 gboolean        tracker_monitor_add                  (TrackerMonitor *monitor,
-						      GFile          *file,
-						      const gchar    *module_name);
+						      const gchar    *module_name,
+						      GFile          *file);
 gboolean        tracker_monitor_remove               (TrackerMonitor *monitor,
-						      GFile          *file,
-						      const gchar    *module_name);
+						      const gchar    *module_name,
+						      GFile          *file);
 gboolean        tracker_monitor_is_watched           (TrackerMonitor *monitor,
-						      GFile          *file,
-						      const gchar    *module_name);
+						      const gchar    *module_name,
+						      GFile          *file);
 gboolean        tracker_monitor_is_watched_by_string (TrackerMonitor *monitor,
-						      const gchar    *path,
-						      const gchar    *module_name);
+						      const gchar    *module_name,
+						      const gchar    *path);
 guint           tracker_monitor_get_count            (TrackerMonitor *monitor,
 						      const gchar    *module_name);
 guint           tracker_monitor_get_ignored          (TrackerMonitor *monitor);

Modified: branches/indexer-split/src/trackerd/tracker-processor.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-processor.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-processor.c	Wed Jul 23 17:59:31 2008
@@ -534,9 +534,35 @@
 		return;
 	}
 
-	/* Set up monitors && recursive monitors */
+	/* Here we set up legacy .cfg options like watch roots */
 	tracker_status_set_and_signal (TRACKER_STATUS_WATCHING);
 
+	if (strcmp (module_name, "files") == 0) {
+		GSList *roots;
+		GSList *l;
+
+		g_message ("  User monitors being added");
+		
+		roots = tracker_config_get_watch_directory_roots (priv->config);
+		for (l = roots; l; l = l->next) {
+			GFile *file;
+			
+			g_message ("    %s", (gchar*) l->data);
+			
+			file = g_file_new_for_path (l->data);
+			tracker_monitor_add (priv->monitor, module_name, file);
+			g_object_unref (file);
+		}
+
+		g_message ("  User crawls being added");
+		roots = tracker_config_get_crawl_directory_roots (priv->config);
+		for (l = roots; l; l = l->next) {
+			g_message ("    %s", (gchar*) l->data);
+		
+			tracker_crawler_add (priv->crawler, l->data);		
+		}
+	}
+	
 	/* Gets all files and directories */
 	tracker_status_set_and_signal (TRACKER_STATUS_PENDING);
 
@@ -752,7 +778,7 @@
 
 	/* Should we add? */
 	if (add_monitor) {
-		tracker_monitor_add (priv->monitor, file, module_name);
+		tracker_monitor_add (priv->monitor, module_name, file);
 	}
 }
 



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