[tracker/extractor-controller-thread: 2/2] tracker-extract: quit on pre-unmount if the mount point any processed file



commit 677723e2e5c317f181aad2ded767cb58d35e49e4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Mar 31 12:21:58 2011 +0200

    tracker-extract: quit on pre-unmount if the mount point any processed file

 src/tracker-extract/tracker-controller.c |   51 ++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/tracker-extract/tracker-controller.c b/src/tracker-extract/tracker-controller.c
index 4c73590..fecd404 100644
--- a/src/tracker-extract/tracker-controller.c
+++ b/src/tracker-extract/tracker-controller.c
@@ -43,11 +43,14 @@ struct TrackerControllerPrivate {
 	GDBusNodeInfo *introspection_data;
 	guint registration_id;
 
+	GList *ongoing_tasks;
+
 	guint shutdown_timeout;
 	guint shutdown_timeout_id;
 };
 
 struct GetMetadataData {
+	TrackerController *controller;
 	GDBusMethodInvocation *invocation;
 	TrackerDBusRequest *request;
 	gchar *uri;
@@ -204,6 +207,42 @@ tracker_controller_class_init (TrackerControllerClass *klass)
 	g_type_class_add_private (object_class, sizeof (TrackerControllerPrivate));
 }
 
+static void
+mount_point_removed_cb (TrackerStorage *storage,
+			const gchar    *uuid,
+			const gchar    *mount_point,
+			gpointer	user_data)
+{
+	TrackerControllerPrivate *priv;
+	gboolean stop = FALSE;
+	GFile *mount_file;
+	GList *l;
+
+	priv = TRACKER_CONTROLLER (user_data)->priv;
+	mount_file = g_file_new_for_path (mount_point);
+
+	for (l = priv->ongoing_tasks; l; l = l->next) {
+		GetMetadataData *data;
+		GFile *task_file;
+
+		data = l->data;
+		task_file = g_file_new_for_uri (data->uri);
+
+		stop = g_file_has_prefix (task_file, mount_file);
+		g_object_unref (task_file);
+
+		if (stop) {
+			break;
+		}
+	}
+
+	if (stop) {
+		g_message ("Mount point '%s' being removed contains files under inspection, quitting",
+			   mount_point);
+		g_main_loop_quit (priv->main_loop);
+	}
+}
+
 static gboolean
 reset_shutdown_timeout_cb (gpointer user_data)
 {
@@ -256,6 +295,8 @@ tracker_controller_init (TrackerController *controller)
 	priv->main_loop = g_main_loop_new (priv->context, FALSE);
 
 	priv->storage = tracker_storage_new ();
+	g_signal_connect (priv->storage, "mount-point-removed",
+	                  G_CALLBACK (mount_point_removed_cb), controller);
 }
 
 static void
@@ -287,10 +328,13 @@ get_metadata_cb (GObject      *object,
 		 GAsyncResult *res,
 		 gpointer      user_data)
 {
+	TrackerControllerPrivate *priv;
 	GetMetadataData *data;
 	TrackerExtractInfo *info;
 
 	data = user_data;
+	priv = data->controller->priv;
+	priv->ongoing_tasks = g_list_remove (priv->ongoing_tasks, data);
 	info = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
 
 	if (info) {
@@ -350,8 +394,10 @@ handle_method_call_get_metadata (TrackerController     *controller,
 	data->mimetype = g_strdup (mime);
 	data->invocation = g_object_ref (invocation);
 	data->request = request;
+	data->controller = controller;
 
 	tracker_extract_file (priv->extractor, uri, mime, get_metadata_cb, data);
+	priv->ongoing_tasks = g_list_prepend (priv->ongoing_tasks, data);
 }
 
 static void
@@ -359,10 +405,13 @@ get_metadata_fast_cb (GObject      *object,
                       GAsyncResult *res,
                       gpointer      user_data)
 {
+	TrackerControllerPrivate *priv;
 	GetMetadataData *data;
 	TrackerExtractInfo *info;
 
 	data = user_data;
+	priv = data->controller->priv;
+	priv->ongoing_tasks = g_list_remove (priv->ongoing_tasks, data);
 	info = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
 
 	if (info) {
@@ -493,8 +542,10 @@ handle_method_call_get_metadata_fast (TrackerController	    *controller,
 			data->fd = fd;
 			data->invocation = invocation;
 			data->request = request;
+			data->controller = controller;
 
 			tracker_extract_file (priv->extractor, uri, mime, get_metadata_fast_cb, data);
+			priv->ongoing_tasks = g_list_prepend (priv->ongoing_tasks, data);
 		} else {
 			tracker_dbus_request_end (request, error);
 			g_dbus_method_invocation_return_dbus_error (invocation,



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