tracker r2424 - in trunk: . src/trackerd



Author: mr
Date: Mon Oct 27 14:53:48 2008
New Revision: 2424
URL: http://svn.gnome.org/viewvc/tracker?rev=2424&view=rev

Log:
	* src/trackerd/tracker-files.c: Small improvement.

	* src/trackerd/tracker-marshal.list: Changed the move signal so we
	actually state if the source was monitored or not. This allows the
	processor to decide if we should try to crawl the target because
	it is new or if it is a simple move operation in the DB.

	* src/trackerd/tracker-monitor.c: get_module_name_from_gfile() was
	incorrectly determining GFile pointers as directories or files. So
	now we do a stat() when we need to know. 

	* src/trackerd/tracker-processor.c: Add some indication in
	debugging if the events we receive are for a file or directory.
	Also call the new function in TrackerCrawler to request traversal
	of a newly found directory upon monitor events.


Modified:
   trunk/ChangeLog
   trunk/src/trackerd/tracker-crawler.c
   trunk/src/trackerd/tracker-crawler.h
   trunk/src/trackerd/tracker-files.c
   trunk/src/trackerd/tracker-marshal.list
   trunk/src/trackerd/tracker-monitor.c
   trunk/src/trackerd/tracker-processor.c

Modified: trunk/src/trackerd/tracker-crawler.c
==============================================================================
--- trunk/src/trackerd/tracker-crawler.c	(original)
+++ trunk/src/trackerd/tracker-crawler.c	Mon Oct 27 14:53:48 2008
@@ -70,7 +70,7 @@
 	 *
 	 *  - 'Paths' are non-recursive.
 	 *  - 'Recurse Paths' are recursive.
-	 *  - 'Special Paths' are paths no in module config.
+	 *  - 'Special Paths' are recursive but not in module config.
 	 */
 	GSList	       *paths;
 	GSList	       *paths_current;
@@ -84,6 +84,7 @@
 	GSList	       *special_paths_current;
 	gboolean	special_paths_are_done;
 
+	/* Ignore/Index patterns */
 	GList	       *ignored_directory_patterns;
 	GList	       *ignored_file_patterns;
 	GList	       *index_file_patterns;
@@ -102,8 +103,9 @@
 	guint		files_ignored;
 
 	/* Status */
-	gboolean	running;
-	gboolean	finished;
+	gboolean	is_running;
+	gboolean	is_finished;
+	gboolean        was_started;
 };
 
 enum {
@@ -603,7 +605,7 @@
 	}
 
 	priv->idle_id = 0;
-	priv->finished = TRUE;
+	priv->is_finished = TRUE;
 
 	tracker_crawler_stop (crawler);
 
@@ -670,7 +672,7 @@
 						     result,
 						     NULL);
 
-	if (!files || !crawler->private->running) {
+	if (!files || !crawler->private->is_running) {
 		/* No more files or we are stopping anyway, so clean
 		 * up and close all file enumerators.
 		 */
@@ -850,6 +852,8 @@
 
 	priv = crawler->private;
 
+	priv->was_started = TRUE;
+
 	g_message ("Crawling directories for module:'%s'",
 		   crawler->private->module_name);
 
@@ -938,12 +942,9 @@
 
 	priv->timer = g_timer_new ();
 
-	/* Set idle handler to process directories and files found */
-	priv->idle_id = g_idle_add (process_func, crawler);
-
 	/* Set as running now */
-	priv->running = TRUE;
-	priv->finished = FALSE;
+	priv->is_running = TRUE;
+	priv->is_finished = FALSE;
 
 	/* Reset stats */
 	priv->directories_found = 0;
@@ -956,6 +957,9 @@
 	priv->recurse_paths_are_done = FALSE;
 	priv->special_paths_are_done = FALSE;
 
+	/* Set idle handler to process directories and files found */
+	priv->idle_id = g_idle_add (process_func, crawler);
+
 	return TRUE;
 }
 
@@ -968,8 +972,9 @@
 
 	priv = crawler->private;
 
+
 	g_message ("  %s crawling files in %4.4f seconds",
-		   priv->finished ? "Finished" : "Stopped",
+		   priv->is_finished ? "Finished" : "Stopped",
 		   g_timer_elapsed (priv->timer, NULL));
 	g_message ("  Found %d directories, ignored %d directories",
 		   priv->directories_found,
@@ -978,14 +983,17 @@
 		   priv->files_found,
 		   priv->files_ignored);
 
-	priv->running = FALSE;
+	priv->is_running = FALSE;
 
 	if (priv->idle_id) {
 		g_source_remove (priv->idle_id);
+		priv->idle_id = 0;
 	}
 
-	g_timer_destroy (priv->timer);
-	priv->timer = NULL;
+	if (priv->timer) {
+		g_timer_destroy (priv->timer);
+		priv->timer = NULL;
+	}
 
 	g_signal_emit (crawler, signals[FINISHED], 0,
 		       priv->module_name,
@@ -995,13 +1003,62 @@
 		       priv->files_ignored);
 }
 
+/* This function is a convenience for the monitor module so we can
+ * just ask it to crawl another path which we didn't know about
+ * before.
+ */
+void
+tracker_crawler_add_unexpected_path (TrackerCrawler *crawler,
+				     const gchar    *path)
+{
+	TrackerCrawlerPrivate *priv;
+	GFile                 *file;
+
+	g_return_if_fail (TRACKER_IS_CRAWLER (crawler));
+	g_return_if_fail (path != NULL);
+
+	priv = crawler->private;
+
+	/* This check should be fine, the reason being, that if we
+	 * call this, it is because we have received a monitor event
+	 * in the first place. This means we must already have been
+	 * started at some point.
+	 */
+	g_return_if_fail (priv->was_started);
+
+	/* FIXME: Should we check paths_are_done to see if we
+	 * need to actually call add_directory()?
+	 */
+	file = g_file_new_for_path (path);
+	add_directory (crawler, file);
+	g_object_unref (file);
+	
+	/* FIXME: Should we reset the stats? */
+	if (!priv->idle_id) {
+		/* Time the event */
+		if (priv->timer) {
+			g_timer_destroy (priv->timer);
+		}
+		
+		priv->timer = g_timer_new ();
+		
+		/* Set as running now */
+		priv->is_running = TRUE;
+		priv->is_finished = FALSE;
+	
+		/* Set idle handler to process directories and files found */
+		priv->idle_id = g_idle_add (process_func, crawler);
+	}
+}
+
+
 /* 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_special_paths_add (TrackerCrawler *crawler,
-				   const gchar	 *path)
+				   const gchar    *path)
 {
 	TrackerCrawlerPrivate *priv;
 
@@ -1010,7 +1067,7 @@
 
 	priv = crawler->private;
 
-	g_return_if_fail (priv->running == FALSE);
+	g_return_if_fail (!priv->is_running);
 
 	priv->special_paths = g_slist_append (priv->special_paths, g_strdup (path));
 }
@@ -1024,6 +1081,8 @@
 
 	priv = crawler->private;
 
+	g_return_if_fail (!priv->is_running);
+
 	g_slist_foreach (priv->special_paths, (GFunc) g_free, NULL);
 	g_slist_free (priv->special_paths);
 	priv->special_paths = NULL;
@@ -1039,6 +1098,8 @@
 
 	priv = crawler->private;
 
+	g_return_if_fail (priv->is_running == FALSE);
+
 	priv->use_module_paths = use_module_paths;
 }
 

Modified: trunk/src/trackerd/tracker-crawler.h
==============================================================================
--- trunk/src/trackerd/tracker-crawler.h	(original)
+++ trunk/src/trackerd/tracker-crawler.h	Mon Oct 27 14:53:48 2008
@@ -55,6 +55,8 @@
 gboolean        tracker_crawler_is_path_ignored     (TrackerCrawler *crawler,
 						     const gchar    *path,
 						     gboolean        is_directory);
+void            tracker_crawler_add_unexpected_path (TrackerCrawler *crawler,
+						     const gchar    *path);
 
 /* Convenience API for old .cfg file */
 void            tracker_crawler_special_paths_add   (TrackerCrawler *crawler,

Modified: trunk/src/trackerd/tracker-files.c
==============================================================================
--- trunk/src/trackerd/tracker-files.c	(original)
+++ trunk/src/trackerd/tracker-files.c	Mon Oct 27 14:53:48 2008
@@ -226,8 +226,6 @@
 static const gchar *
 get_file_id_and_db_service (const gchar *uri, gint *id)
 {
-	*id = 0;
-
 	*id = tracker_db_file_get_id (TRACKER_DB_FOR_FILE_SERVICE, uri);
 	if (*id) {
 		return TRACKER_DB_FOR_FILE_SERVICE;
@@ -313,7 +311,6 @@
 	value = tracker_ontology_get_service_by_mime (mime);
 
 	if (value) {
-
 		tracker_dbus_request_comment (request_id,
 					      "Info for file '%s', "
 					      "id:%d, mime:'%s', service:'%s'",
@@ -334,10 +331,8 @@
 		dbus_g_method_return_error (context, actual_error);
 		g_error_free (actual_error);
 	}
-
 }
 
-
 void
 tracker_files_get_text_contents (TrackerFiles		*object,
 				 const gchar		*uri,

Modified: trunk/src/trackerd/tracker-marshal.list
==============================================================================
--- trunk/src/trackerd/tracker-marshal.list	(original)
+++ trunk/src/trackerd/tracker-marshal.list	Mon Oct 27 14:53:48 2008
@@ -3,7 +3,7 @@
 VOID:STRING,STRING,STRING
 VOID:STRING,BOOLEAN,BOOLEAN,BOOLEAN,BOOLEAN,BOOLEAN,BOOLEAN
 VOID:STRING,OBJECT,BOOLEAN
-VOID:STRING,OBJECT,OBJECT,BOOLEAN
+VOID:STRING,OBJECT,OBJECT,BOOLEAN,BOOLEAN
 VOID:STRING,OBJECT
 VOID:BOXED
 

Modified: trunk/src/trackerd/tracker-monitor.c
==============================================================================
--- trunk/src/trackerd/tracker-monitor.c	(original)
+++ trunk/src/trackerd/tracker-monitor.c	Mon Oct 27 14:53:48 2008
@@ -198,12 +198,13 @@
 			      G_SIGNAL_RUN_LAST,
 			      0,
 			      NULL, NULL,
-			      tracker_marshal_VOID__STRING_OBJECT_OBJECT_BOOLEAN,
+			      tracker_marshal_VOID__STRING_OBJECT_OBJECT_BOOLEAN_BOOLEAN,
 			      G_TYPE_NONE,
-			      4,
+			      5,
 			      G_TYPE_STRING,
 			      G_TYPE_OBJECT,
 			      G_TYPE_OBJECT,
+			      G_TYPE_BOOLEAN,
 			      G_TYPE_BOOLEAN);
 
 	g_object_class_install_property (object_class,
@@ -571,11 +572,15 @@
 		g_object_unref (parent);
 
 		if (!module_name) {
-			gchar *child_path;
 			gchar *parent_path;
+			gchar *child_path;
 
-			child_path = g_file_get_path (file);
 			parent_path = g_file_get_path (parent);
+			child_path = g_file_get_path (file);
+
+			if (is_directory) {
+				*is_directory = g_file_test (child_path, G_FILE_TEST_IS_DIR);
+			}
 
 			g_warning ("Could not get module name from GFile (path:'%s' or parent:'%s')",
 				   child_path,
@@ -585,10 +590,14 @@
 			g_free (child_path);
 
 			return NULL;
-		}
+		} else {
+			if (is_directory) {
+				gchar *child_path;
 
-		if (is_directory) {
-			*is_directory = FALSE;
+				child_path = g_file_get_path (file);
+				*is_directory = g_file_test (child_path, G_FILE_TEST_IS_DIR);
+				g_free (child_path);
+			}
 		}
 	}
 
@@ -1186,10 +1195,8 @@
 	}
 
 	other_file = NULL;
+	module_name = get_module_name_from_gfile (monitor, file, &is_directory);
 
-	module_name = get_module_name_from_gfile (monitor,
-						  file,
-						  &is_directory);
 	if (!module_name) {
 		g_free (str1);
 		g_object_unref (file);
@@ -1341,7 +1348,8 @@
 					       module_name,
 					       file,
 					       other_file,
-					       is_directory);
+					       is_directory, 
+					       TRUE);
 				g_hash_table_remove (monitor->private->event_pairs,
 						     GUINT_TO_POINTER (cookie));
 			}
@@ -1366,9 +1374,6 @@
 			break;
 
 		case IN_MOVED_TO:
-			/* FIXME: What if we don't monitor the other
-			 * location?
-			 */
 			if (cookie == 0) {
 				g_signal_emit (monitor,
 					       signals[ITEM_CREATED], 0,
@@ -1376,12 +1381,32 @@
 					       file,
 					       is_directory);
 			} else if (other_file) {
+				gboolean is_source_indexed;
+
+				/* We check for the event pair in the
+				 * hash table here. If it doesn't
+				 * exist even though we have a cookie
+				 * it means we didn't have a monitor
+				 * set up on the source location.
+				 * This means we need to get the
+				 * processor to crawl the new
+				 * location.
+				 */
+
+				if (g_hash_table_lookup (monitor->private->event_pairs, 
+							 GUINT_TO_POINTER (cookie))) {
+					is_source_indexed = TRUE;
+				} else {
+					is_source_indexed = FALSE;
+				}
+
 				g_signal_emit (monitor,
 					       signals[ITEM_MOVED], 0,
 					       module_name,
 					       other_file,
 					       file,
-					       is_directory);
+					       is_directory,
+					       is_source_indexed);
 				g_hash_table_remove (monitor->private->event_pairs,
 						     GUINT_TO_POINTER (cookie));
 			}

Modified: trunk/src/trackerd/tracker-processor.c
==============================================================================
--- trunk/src/trackerd/tracker-processor.c	(original)
+++ trunk/src/trackerd/tracker-processor.c	Mon Oct 27 14:53:48 2008
@@ -140,6 +140,7 @@
 					     GFile	      *file,
 					     GFile	      *other_file,
 					     gboolean	       is_directory,
+					     gboolean          is_source_monitored,
 					     gpointer	       user_data);
 static void crawler_processing_file_cb	    (TrackerCrawler   *crawler,
 					     const gchar      *module_name,
@@ -1145,20 +1146,23 @@
 	crawler = g_hash_table_lookup (processor->private->crawlers, module_name);
 	ignored = tracker_crawler_is_path_ignored (crawler, path, is_directory);
 
-	g_debug ("%s:'%s' (create monitor event or user request)",
+	g_debug ("%s:'%s' (%s) (create monitor event or user request)",
 		 ignored ? "Ignored" : "Found ",
-		 path);
-
-	g_free (path);
+		 path,
+		 is_directory ? "DIR" : "FILE");
 
-	if (ignored) {
-		return;
+	if (!ignored) {
+		if (!is_directory) {
+			queue = g_hash_table_lookup (processor->private->items_created_queues, module_name);
+			g_queue_push_tail (queue, g_object_ref (file));
+			
+			item_queue_handlers_set_up (processor);
+		} else {
+			tracker_crawler_add_unexpected_path (crawler, path);
+		}
 	}
 
-	queue = g_hash_table_lookup (processor->private->items_created_queues, module_name);
-	g_queue_push_tail (queue, g_object_ref (file));
-
-	item_queue_handlers_set_up (processor);
+	g_free (path);
 }
 
 static void
@@ -1176,20 +1180,19 @@
 	crawler = g_hash_table_lookup (processor->private->crawlers, module_name);
 	ignored = tracker_crawler_is_path_ignored (crawler, path, is_directory);
 
-	g_debug ("%s:'%s' (update monitor event or user request)",
+	g_debug ("%s:'%s' (%s) (update monitor event or user request)",
 		 ignored ? "Ignored" : "Found ",
-		 path);
-
-	g_free (path);
+		 path,
+		 is_directory ? "DIR" : "FILE");
 
-	if (ignored) {
-		return;
+	if (!ignored) {
+		queue = g_hash_table_lookup (processor->private->items_updated_queues, module_name);
+		g_queue_push_tail (queue, g_object_ref (file));
+		
+		item_queue_handlers_set_up (processor);
 	}
 
-	queue = g_hash_table_lookup (processor->private->items_updated_queues, module_name);
-	g_queue_push_tail (queue, g_object_ref (file));
-
-	item_queue_handlers_set_up (processor);
+	g_free (path);
 }
 
 static void
@@ -1207,20 +1210,19 @@
 	crawler = g_hash_table_lookup (processor->private->crawlers, module_name);
 	ignored = tracker_crawler_is_path_ignored (crawler, path, is_directory);
 
-	g_debug ("%s:'%s' (delete monitor event or user request)",
+	g_debug ("%s:'%s' (%s) (delete monitor event or user request)",
 		 ignored ? "Ignored" : "Found ",
-		 path);
-
-	g_free (path);
+		 path,
+		 is_directory ? "DIR" : "FILE");
 
-	if (ignored) {
-		return;
+	if (!ignored) {
+		queue = g_hash_table_lookup (processor->private->items_deleted_queues, module_name);
+		g_queue_push_tail (queue, g_object_ref (file));
+		
+		item_queue_handlers_set_up (processor);
 	}
 
-	queue = g_hash_table_lookup (processor->private->items_deleted_queues, module_name);
-	g_queue_push_tail (queue, g_object_ref (file));
-
-	item_queue_handlers_set_up (processor);
+	g_free (path);
 }
 
 static void
@@ -1244,34 +1246,43 @@
 	path_ignored = tracker_crawler_is_path_ignored (crawler, path, is_directory);
 	other_path_ignored = tracker_crawler_is_path_ignored (crawler, other_path, is_directory);
 
-	g_debug ("%s:'%s'->'%s':%s (move monitor event or user request)",
+	g_debug ("%s:'%s'->'%s':%s (%s) (move monitor event or user request)",
 		 path_ignored ? "Ignored" : "Found ",
 		 path,
 		 other_path,
-		 other_path_ignored ? "Ignored" : " Found");
-
-	g_free (other_path);
-	g_free (path);
+		 other_path_ignored ? "Ignored" : " Found",
+		 is_directory ? "DIR" : "FILE");
 
 	if (path_ignored && other_path_ignored) {
 		/* Do nothing */
-		return;
 	} else if (path_ignored) {
 		/* Check new file */
-		queue = g_hash_table_lookup (processor->private->items_created_queues, module_name);
-		g_queue_push_tail (queue, g_object_ref (other_file));
+		if (!is_directory) {
+			queue = g_hash_table_lookup (processor->private->items_created_queues, module_name);
+			g_queue_push_tail (queue, g_object_ref (other_file));
+
+			item_queue_handlers_set_up (processor);
+		}
+
+		/* If this is a directory we need to crawl it */
+		tracker_crawler_add_unexpected_path (crawler, other_path);
 	} else if (other_path_ignored) {
 		/* Delete old file */
 		queue = g_hash_table_lookup (processor->private->items_deleted_queues, module_name);
 		g_queue_push_tail (queue, g_object_ref (file));
+
+		item_queue_handlers_set_up (processor);
 	} else {
 		/* Move old file to new file */
 		queue = g_hash_table_lookup (processor->private->items_moved_queues, module_name);
 		g_queue_push_tail (queue, g_object_ref (file));
 		g_queue_push_tail (queue, g_object_ref (other_file));
+
+		item_queue_handlers_set_up (processor);
 	}
 
-	item_queue_handlers_set_up (processor);
+	g_free (other_path);
+	g_free (path);
 }
 
 static void
@@ -1310,9 +1321,24 @@
 		       GFile	      *file,
 		       GFile	      *other_file,
 		       gboolean        is_directory,
+		       gboolean        is_source_monitored,
 		       gpointer        user_data)
 {
-	processor_files_move (user_data, module_name, file, other_file, is_directory);
+	if (!is_source_monitored) {
+		TrackerProcessor *processor;
+		TrackerCrawler   *crawler;
+		gchar            *path;
+
+		processor = user_data;
+
+		/* If the source is not monitored, we need to crawl it. */
+		path = g_file_get_path (other_file);
+		crawler = g_hash_table_lookup (processor->private->crawlers, module_name);
+		tracker_crawler_add_unexpected_path (crawler, path);
+		g_free (path);
+	} else {
+		processor_files_move (user_data, module_name, file, other_file, is_directory);
+	}
 }
 
 static void
@@ -1611,7 +1637,7 @@
 	g_return_if_fail (TRACKER_IS_PROCESSOR (processor));
 	g_return_if_fail (module_name != NULL);
 	g_return_if_fail (G_IS_FILE (file));
-
+	
 	processor_files_check (processor, module_name, file, is_directory);
 }
 



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