[tracker/tracker-0.6] Fix not crawling inserted removable media



commit 754003d1dd2f2bbcef225450639f77e313d9a1c2
Author: Martyn Russell <martyn imendio com>
Date:   Wed May 13 17:35:07 2009 +0100

    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      |  119 ++++++++++++++++++++++++++++++-------
 src/trackerd/tracker-processor.c |   53 ++++-------------
 src/trackerd/tracker-processor.h |   56 ++++++++++--------
 3 files changed, 141 insertions(+), 87 deletions(-)

diff --git a/src/trackerd/tracker-main.c b/src/trackerd/tracker-main.c
index f748b6d..a796ece 100644
--- a/src/trackerd/tracker-main.c
+++ b/src/trackerd/tracker-main.c
@@ -94,6 +94,17 @@
 #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,
@@ -658,27 +669,61 @@ crawling_finished_cb (TrackerProcessor *processor,
 
 #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 ("Indexer couldn't set volume state for:'%s' in database, %s", 
-			    (gchar*) user_data,
+			    mpu->udi,
 			    error ? error->message : "no error given");
+
 		g_error_free (error);
 
 		tracker_shutdown ();
 	} else {
 		g_message ("Indexer has now set the state for the volume with UDI:");
-		g_message ("  %s", (gchar*) user_data);
+		g_message ("  %s", mpu->udi);
 	}
 		
-	g_free (user_data);
-
 	/* See if we have any more callbacks here, if we don't we can
 	 * signal the stats to update.
 	 */
@@ -699,7 +744,11 @@ mount_point_set_cb (DBusGProxy *proxy,
 		/* Unpause the indexer */
 		tracker_status_set_is_paused_for_dbus (FALSE);
 			
-		if (!private->mount_points_up) {
+		/* Don't try to quit the main loop twice if we have
+		 * had an error above.
+		 */
+		if (!private->mount_points_up && 
+		    !private->shutdown) {
 			private->mount_points_up = TRUE;
 
 			/* We need to stop the main loop, we started
@@ -713,6 +762,28 @@ mount_point_set_cb (DBusGProxy *proxy,
 			   private->mount_points_to_set,
 			   private->mount_points_to_set == 1 ? "volume" : "volumes");
 	}
+
+	/* 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
@@ -722,6 +793,7 @@ mount_point_added_cb (TrackerHal  *hal,
 		      gpointer	   user_data)
 {
 	TrackerMainPrivate *private;
+	MountPointUpdate   *mpu;
 	
 	private = g_static_private_get (&private_key);
 
@@ -732,12 +804,13 @@ mount_point_added_cb (TrackerHal  *hal,
 	g_message ("Indexer is being notified about added volume with 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
@@ -747,7 +820,8 @@ mount_point_removed_cb (TrackerHal  *hal,
 			gpointer     user_data)
 {
 	TrackerMainPrivate *private;
-	
+	MountPointUpdate   *mpu;
+
 	private = g_static_private_get (&private_key);
 
 	private->mount_points_to_set++;
@@ -757,12 +831,13 @@ mount_point_removed_cb (TrackerHal  *hal,
 	g_message ("Indexer is being notified about removed volume with 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_cb,
-								   g_strdup (udi));
+								   mpu);
 }
 
 static void
@@ -793,24 +868,22 @@ set_up_mount_points_cb (DBusGProxy *proxy,
 		g_message ("Indexer is being notified about volume states with UDIs:");
 
 		for (l = roots; l; l = l->next) {
-			gchar       *udi;
-			const gchar *mount_point;
-			gboolean     is_mounted;
-			
-			udi = l->data;
-			mount_point = tracker_hal_udi_get_mount_point (hal, udi);
-			is_mounted = tracker_hal_udi_get_is_mounted (hal, udi);
-			
-			g_message ("  %s", udi);
-			
+			MountPointUpdate *mpu;
+
 			private->mount_points_to_set++;
-			
+			mpu = mount_point_update_new (l->data, 
+						      tracker_hal_udi_get_mount_point (hal, l->data),
+						      TRUE, 
+						      tracker_hal_udi_get_is_mounted (hal, l->data));	
+		
+			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 9ba3fec..bfa4202 100644
--- a/src/trackerd/tracker-processor.c
+++ b/src/trackerd/tracker-processor.c
@@ -164,17 +164,6 @@ static void crawler_finished_cb		    (TrackerCrawler   *crawler,
 					     guint	       files_ignored,
 					     gpointer	       user_data);
 
-#ifdef HAVE_HAL
-static void mount_point_added_cb	    (TrackerHal       *hal,
-					     const gchar      *volume_uuid,
-					     const gchar      *mount_point,
-					     gpointer	       user_data);
-static void mount_point_removed_cb	    (TrackerHal       *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)
@@ -334,13 +323,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 */
@@ -1525,18 +1507,17 @@ crawler_finished_cb (TrackerCrawler *crawler,
 
 #ifdef HAVE_HAL
 
-static void
-mount_point_added_cb (TrackerHal  *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;
 
-	processor = user_data;
+	g_return_if_fail (TRACKER_IS_PROCESSOR (processor));
+
 	priv = processor->private;
 
 	status = tracker_status_get ();
@@ -1569,22 +1550,21 @@ mount_point_added_cb (TrackerHal  *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 (TrackerHal  *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;
 
-	processor = user_data;
+	g_return_if_fail (TRACKER_IS_PROCESSOR (processor));
+
 	priv = processor->private;
 
 	/* Remove directory from list of iterated_removable_media, so
@@ -1651,13 +1631,6 @@ tracker_processor_new (TrackerConfig *config,
 	priv->removable_devices = tracker_hal_get_removable_device_roots (priv->hal);
 	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 d90af73..e883a2a 100644
--- a/src/trackerd/tracker-processor.h
+++ b/src/trackerd/tracker-processor.h
@@ -52,39 +52,47 @@ struct TrackerProcessorClass {
 };
 
 GType		  tracker_processor_get_type		    (void) G_GNUC_CONST;
-
-TrackerProcessor *tracker_processor_new			    (TrackerConfig    *config,
+TrackerProcessor *tracker_processor_new                     (TrackerConfig    *config,
 							     TrackerHal       *hal);
-void		  tracker_processor_start		    (TrackerProcessor *processor);
-void		  tracker_processor_stop		    (TrackerProcessor *processor);
+void              tracker_processor_start                   (TrackerProcessor *processor);
+void              tracker_processor_stop                    (TrackerProcessor *processor);
+
 
 /* Required API for org.freedesktop.Tracker.Files */
-void		  tracker_processor_files_check		    (TrackerProcessor *processor,
+void              tracker_processor_files_check             (TrackerProcessor *processor,
 							     const gchar      *module_name,
-							     GFile	      *file,
-							     gboolean	       is_directory);
-void		  tracker_processor_files_update	    (TrackerProcessor *processor,
+							     GFile            *file,
+							     gboolean          is_directory);
+void              tracker_processor_files_update            (TrackerProcessor *processor,
 							     const gchar      *module_name,
-							     GFile	      *file,
-							     gboolean	       is_directory);
-void		  tracker_processor_files_delete	    (TrackerProcessor *processor,
+							     GFile            *file,
+							     gboolean          is_directory);
+void              tracker_processor_files_delete            (TrackerProcessor *processor,
 							     const gchar      *module_name,
-							     GFile	      *file,
-							     gboolean	       is_directory);
-void		  tracker_processor_files_move		    (TrackerProcessor *processor,
+							     GFile            *file,
+							     gboolean          is_directory);
+void              tracker_processor_files_move              (TrackerProcessor *processor,
 							     const gchar      *module_name,
-							     GFile	      *file,
-							     GFile	      *other_file,
-							     gboolean	       is_directory);
+							     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);
-guint		  tracker_processor_get_directories_ignored (TrackerProcessor *processor);
-guint		  tracker_processor_get_directories_total   (TrackerProcessor *processor);
-guint		  tracker_processor_get_files_found	    (TrackerProcessor *processor);
-guint		  tracker_processor_get_files_ignored	    (TrackerProcessor *processor);
-guint		  tracker_processor_get_files_total	    (TrackerProcessor *processor);
-gdouble		  tracker_processor_get_seconds_elapsed     (TrackerProcessor *processor);
+guint             tracker_processor_get_directories_found   (TrackerProcessor *processor);
+guint             tracker_processor_get_directories_ignored (TrackerProcessor *processor);
+guint             tracker_processor_get_directories_total   (TrackerProcessor *processor);
+guint             tracker_processor_get_files_found         (TrackerProcessor *processor);
+guint             tracker_processor_get_files_ignored       (TrackerProcessor *processor);
+guint             tracker_processor_get_files_total         (TrackerProcessor *processor);
+gdouble           tracker_processor_get_seconds_elapsed     (TrackerProcessor *processor);
 
 G_END_DECLS
 



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