[tracker/extractor-controller-thread: 2/2] tracker-extract: quit on pre-unmount if the mount point any processed file
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/extractor-controller-thread: 2/2] tracker-extract: quit on pre-unmount if the mount point any processed file
- Date: Thu, 7 Apr 2011 13:30:20 +0000 (UTC)
commit 0c942e558805ba23eed027b29032512e2b025c1d
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 | 55 ++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/src/tracker-extract/tracker-controller.c b/src/tracker-extract/tracker-controller.c
index 5487c08..bb28650 100644
--- a/src/tracker-extract/tracker-controller.c
+++ b/src/tracker-extract/tracker-controller.c
@@ -43,6 +43,8 @@ struct TrackerControllerPrivate {
GDBusNodeInfo *introspection_data;
guint registration_id;
+ GList *ongoing_tasks;
+
guint shutdown_timeout;
guint shutdown_timeout_id;
@@ -243,6 +245,49 @@ metadata_data_free (GetMetadataData *data)
g_slice_free (GetMetadataData, data);
}
+static void
+mount_point_removed_cb (TrackerStorage *storage,
+ const gchar *uuid,
+ const gchar *mount_point,
+ gpointer user_data)
+{
+ TrackerControllerPrivate *priv;
+ GFile *mount_file;
+ GList *elem;
+
+ priv = TRACKER_CONTROLLER (user_data)->priv;
+ mount_file = g_file_new_for_path (mount_point);
+
+ for (elem = priv->ongoing_tasks; elem; elem = elem->next) {
+ GetMetadataData *data;
+ GFile *task_file;
+
+ data = elem->data;
+ task_file = g_file_new_for_uri (data->uri);
+
+ if (g_file_has_prefix (task_file, mount_file)) {
+ /* Mount path contains one of the files being processed */
+ if (!elem->next) {
+ /* The last element in the list is
+ * the one currently being processed,
+ * so exit abruptly.
+ */
+ g_message ("Mount point '%s' being removed contains "
+ "current file under inspection ('%s'), quitting",
+ mount_point, data->uri);
+ g_main_loop_quit (priv->main_loop);
+ } else {
+ g_message ("Mount point '%s' being removed affects "
+ "file waiting for inspection ('%s'), cancelling it",
+ mount_point, data->uri);
+ g_cancellable_cancel (data->cancellable);
+ }
+ }
+
+ g_object_unref (task_file);
+ }
+}
+
static gboolean
reset_shutdown_timeout_cb (gpointer user_data)
{
@@ -295,6 +340,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);
priv->initialization_cond = g_cond_new ();
priv->initialization_mutex = g_mutex_new ();
@@ -329,10 +376,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) {
@@ -386,6 +436,7 @@ handle_method_call_get_metadata (TrackerController *controller,
data = metadata_data_new (controller, uri, mime, invocation, request);
tracker_extract_file (priv->extractor, uri, mime, data->cancellable,
get_metadata_cb, data);
+ priv->ongoing_tasks = g_list_prepend (priv->ongoing_tasks, data);
}
static void
@@ -393,10 +444,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) {
@@ -523,6 +577,7 @@ handle_method_call_get_metadata_fast (TrackerController *controller,
tracker_extract_file (priv->extractor, uri, mime, data->cancellable,
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]