[tracker] Fix not crawling inserted removable media



commit 95b0d5692192c3c3ced11269ca8619ccff682ee5
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Jun 12 11:23:26 2009 +0200

    Fix not crawling inserted removable media
    
    Now we start the processor again when we get new removable media
    inserted, this bug mainly affects the condition when we have finished
    processing all files and the removable media state changes again.
    
    The statistics we report about files crawled and time taken is now
    reset and correct each time this occurs.
    
    The mount point added and removed callbacks from HAL were removed in
    TrackerProcessor and now two functions are called FROM tracker-main.c
    which do the same thing. The reason for this, is that we change state
    while setting volume states and we can't process removable media in
    some states. So to control this we do everything AFTER we have set the
    removable media states correctly.

 src/trackerd/tracker-main.c      |  117 ++++++++++++++++++++++++++++++++------
 src/trackerd/tracker-processor.c |   52 ++++-------------
 src/trackerd/tracker-processor.h |    8 +++
 3 files changed, 120 insertions(+), 57 deletions(-)
---
diff --git a/src/trackerd/tracker-main.c b/src/trackerd/tracker-main.c
index 52a41a8..7ff7e62 100644
--- a/src/trackerd/tracker-main.c
+++ b/src/trackerd/tracker-main.c
@@ -93,6 +93,18 @@
 #define THROTTLE_DEFAULT	    0
 #define THROTTLE_DEFAULT_ON_BATTERY 5
 
+
+#ifdef HAVE_HAL
+
+typedef struct {
+	gchar *udi;
+	gchar *mount_point;
+	gboolean no_crawling;
+	gboolean was_added;
+} MountPointUpdate;
+
+#endif /* HAVE_HAL */
+
 typedef enum {
 	TRACKER_RUNNING_NON_ALLOWED,
 	TRACKER_RUNNING_READONLY,
@@ -309,13 +321,51 @@ check_runtime_level (TrackerConfig *config,
 
 #ifdef HAVE_HAL
 
+static MountPointUpdate *
+mount_point_update_new (const gchar *udi,
+			const gchar *mount_point,
+			gboolean no_crawling,
+			gboolean was_added)
+{
+	MountPointUpdate *mpu;
+
+	mpu = g_slice_new0 (MountPointUpdate);
+
+	mpu->udi = g_strdup (udi);
+	mpu->mount_point = g_strdup (mount_point);
+
+	mpu->no_crawling = no_crawling;
+	mpu->was_added = was_added;
+
+	return mpu;
+}
+
+static void
+mount_point_update_free (MountPointUpdate *mpu)
+{
+	if (!mpu) {
+		return;
+	}
+
+	g_free (mpu->mount_point);
+	g_free (mpu->udi);
+
+	g_slice_free (MountPointUpdate, mpu);
+}
+
 static void
 mount_point_set_cb (DBusGProxy *proxy, 
 		    GError     *error, 
 		    gpointer    user_data)
 {
+	TrackerMainPrivate *private;
+	MountPointUpdate *mpu;
+
+	mpu = user_data;
+
 	if (error) {
-		g_critical ("Couldn't set mount point state, %s", 
+		g_critical ("Couldn't set mount point state for:'%s' in database, %s", 
+			    mpu->udi,
 			    error->message);
 		g_error_free (error);
 		g_free (user_data);
@@ -323,9 +373,37 @@ mount_point_set_cb (DBusGProxy *proxy,
 	}
 
 	g_message ("Indexer now knows about UDI state:");
-	g_message ("  %s", (gchar*) user_data);
+	g_message ("  %s", mpu->udi);
 
-	g_free (user_data);
+	/* Merging: tracker-0.6 appears to have code here that we don't
+	 *
+	 * if (!private->mount_points_up ...
+	 */
+
+	private = g_static_private_get (&private_key);
+
+	/* Make sure we crawl any new mount points or stop crawling
+	 * any mount points. We do it this way instead of listening
+	 * for the same HAL signals in the processor because the
+	 * processor checks state and at the time, we are PAUSED which
+	 * causes us state machine problems.
+	 *
+	 * This is the easiest way to do it.
+	 */
+
+	 if (!mpu->no_crawling) {
+		 if (mpu->was_added) {
+			 tracker_processor_mount_point_added (private->processor,
+							      mpu->udi,
+							      mpu->mount_point);
+		 } else {
+			 tracker_processor_mount_point_removed (private->processor,
+								mpu->udi,
+								mpu->mount_point);
+		}
+	}
+
+	mount_point_update_free (mpu);
 }
 
 static void
@@ -335,18 +413,20 @@ mount_point_added_cb (TrackerStorage *hal,
 		      gpointer	      user_data)
 {
 	TrackerMainPrivate *private;
-	
+	MountPointUpdate *mpu;
+
 	private = g_static_private_get (&private_key);
 
 	g_message ("Indexer is being notified about added UDI:");
 	g_message ("  %s", udi);
 
+	mpu = mount_point_update_new (udi, mount_point, FALSE, TRUE);
 	org_freedesktop_Tracker_Indexer_volume_update_state_async (tracker_dbus_indexer_get_proxy (), 
 								   udi,
 								   mount_point,
 								   TRUE,
 								   mount_point_set_cb,
-								   g_strdup (udi));
+								   mpu);
 }
 
 static void
@@ -383,18 +463,20 @@ mount_point_removed_cb (TrackerStorage  *hal,
 			gpointer         user_data)
 {
 	TrackerMainPrivate *private;
-	
+	MountPointUpdate *mpu;
+
 	private = g_static_private_get (&private_key);
 
 	g_message ("Indexer is being notified about removed UDI:");
 	g_message ("  %s", udi);
 
+	mpu = mount_point_update_new (udi, mount_point, FALSE, FALSE);
 	org_freedesktop_Tracker_Indexer_volume_update_state_async (tracker_dbus_indexer_get_proxy (), 
 								   udi,
 								   mount_point,
 								   FALSE,
 								   mount_point_set_and_signal_cb,
-								   g_strdup (udi));
+								   mpu);
 }
 
 #endif /* HAVE_HAL */
@@ -765,22 +847,21 @@ set_up_mount_points_cb (DBusGProxy *proxy,
 	roots = tracker_storage_get_removable_device_udis (hal);
 	
 	for (l = roots; l; l = l->next) {
-		gchar       *udi;
-		const gchar *mount_point;
-		gboolean     is_mounted;
+		MountPointUpdate *mpu;
 
-		udi = l->data;
-		mount_point = tracker_storage_udi_get_mount_point (hal, udi);
-		is_mounted = tracker_storage_udi_get_is_mounted (hal, udi);
+		mpu = mount_point_update_new (l->data,
+					      tracker_storage_udi_get_mount_point (hal, l->data),
+					      TRUE,
+					      tracker_storage_udi_get_is_mounted (hal, l->data));
 
-		g_message ("  %s", udi);
+		g_message (" %s", mpu->udi);
 
 		org_freedesktop_Tracker_Indexer_volume_update_state_async (tracker_dbus_indexer_get_proxy (), 
-									   udi,
-									   mount_point,
-									   is_mounted,
+									   mpu->udi,
+									   mpu->mount_point,
+									   mpu->was_added,
 									   mount_point_set_cb,
-									   g_strdup (udi));
+									   mpu);
 	}
 
 	g_list_free (roots);
diff --git a/src/trackerd/tracker-processor.c b/src/trackerd/tracker-processor.c
index fa7a7e2..229b07e 100644
--- a/src/trackerd/tracker-processor.c
+++ b/src/trackerd/tracker-processor.c
@@ -162,17 +162,6 @@ static void crawler_finished_cb		    (TrackerCrawler   *crawler,
 					     guint	       files_ignored,
 					     gpointer	       user_data);
 
-#ifdef HAVE_HAL
-static void mount_point_added_cb	    (TrackerStorage   *hal,
-					     const gchar      *volume_uuid,
-					     const gchar      *mount_point,
-					     gpointer	       user_data);
-static void mount_point_removed_cb	    (TrackerStorage   *hal,
-					     const gchar      *volume_uuid,
-					     const gchar      *mount_point,
-					     gpointer	       user_data);
-#endif /* HAVE_HAL */
-
 static guint signals[LAST_SIGNAL] = { 0, };
 
 G_DEFINE_TYPE (TrackerProcessor, tracker_processor, G_TYPE_OBJECT)
@@ -332,13 +321,6 @@ tracker_processor_finalize (GObject *object)
 	}
 
 	if (priv->hal) {
-		g_signal_handlers_disconnect_by_func (priv->hal,
-						      mount_point_added_cb,
-						      object);
-		g_signal_handlers_disconnect_by_func (priv->hal,
-						      mount_point_removed_cb,
-						      object);
-
 		g_object_unref (priv->hal);
 	}
 #endif /* HAVE_HAL */
@@ -1510,19 +1492,18 @@ normalize_mount_point (const gchar *mount_point)
 	}
 }
 
-static void
-mount_point_added_cb (TrackerStorage  *hal,
-		      const gchar *udi,
-		      const gchar *mount_point,
-		      gpointer	   user_data)
+void
+tracker_processor_mount_point_added (TrackerProcessor *processor,
+				     const gchar *udi,
+				     const gchar *mount_point)
 {
-	TrackerProcessor        *processor;
 	TrackerProcessorPrivate *priv;
 	TrackerStatus	         status;
 	GList                   *l;
 	gchar                   *mp;
 
-	processor = user_data;
+	g_return_if_fail (TRACKER_IS_PROCESSOR (processor));
+
 	priv = processor->private;
 
 	status = tracker_status_get ();
@@ -1555,23 +1536,22 @@ mount_point_added_cb (TrackerStorage  *hal,
 		 * crawled all locations so we need to start up the
 		 * processor again for the removable media once more.
 		 */
-		process_module_next (processor);
+		tracker_processor_start (processor);
 	}
 }
 
-static void
-mount_point_removed_cb (TrackerStorage  *hal,
-			const gchar *udi,
-			const gchar *mount_point,
-			gpointer     user_data)
+void
+tracker_processor_mount_point_removed (TrackerProcessor *processor,
+				       const gchar *udi,
+				       const gchar *mount_point)
 {
-	TrackerProcessor        *processor;
 	TrackerProcessorPrivate *priv;
 	GFile		        *file;
 	GList                   *l;
 	gchar                   *mp;
 
-	processor = user_data;
+	g_return_if_fail (TRACKER_IS_PROCESSOR (processor));
+
 	priv = processor->private;
 	mp = normalize_mount_point (mount_point);
 
@@ -1642,12 +1622,6 @@ tracker_processor_new (TrackerConfig  *config,
 	priv->removable_devices_current = priv->removable_devices;
 	priv->removable_devices_completed = NULL;
 
-	g_signal_connect (priv->hal, "mount-point-added",
-			  G_CALLBACK (mount_point_added_cb),
-			  processor);
-	g_signal_connect (priv->hal, "mount-point-removed",
-			  G_CALLBACK (mount_point_removed_cb),
-			  processor);
 #endif /* HAVE_HAL */
 
 	/* Set up the crawlers now we have config and hal */
diff --git a/src/trackerd/tracker-processor.h b/src/trackerd/tracker-processor.h
index 45900bd..3c2cb2e 100644
--- a/src/trackerd/tracker-processor.h
+++ b/src/trackerd/tracker-processor.h
@@ -76,6 +76,14 @@ void		  tracker_processor_files_move		    (TrackerProcessor *processor,
 							     GFile	      *file,
 							     GFile	      *other_file,
 							     gboolean	       is_directory);
+#ifdef HAVE_HAL
+void		  tracker_processor_mount_point_added 	     (TrackerProcessor *processor,
+							      const gchar *udi,
+							      const gchar *mount_point);
+void		  tracker_processor_mount_point_removed     (TrackerProcessor *processor,
+							      const gchar *udi,
+							      const gchar *mount_point);
+#endif /* HAVE_HAL */
 
 /* Statistics */
 guint		  tracker_processor_get_directories_found   (TrackerProcessor *processor);



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