[tracker-miners/wip/carlosg/cli-improvements: 9/30] tracker-extract: Remove files from persistence after cancellation
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/cli-improvements: 9/30] tracker-extract: Remove files from persistence after cancellation
- Date: Tue, 18 Aug 2020 09:18:31 +0000 (UTC)
commit 9583c198ab1fe3c39d4896cb50c16799c3b6d9f2
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Aug 16 15:08:39 2020 +0200
tracker-extract: Remove files from persistence after cancellation
Move all cancellation handling closer to the TrackerExtractDecorator, so
we can pull files off persistence handling, since cancellation shouldn't
be considered an error on a future execution.
We still should exit ASAP, though.
src/tracker-extract/tracker-extract-decorator.c | 37 +++++++++++++++++++++++++
src/tracker-extract/tracker-extract.c | 34 -----------------------
2 files changed, 37 insertions(+), 34 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-decorator.c b/src/tracker-extract/tracker-extract-decorator.c
index 8a45cab17..804f19f49 100644
--- a/src/tracker-extract/tracker-extract-decorator.c
+++ b/src/tracker-extract/tracker-extract-decorator.c
@@ -40,6 +40,8 @@ struct _ExtractData {
TrackerDecorator *decorator;
TrackerDecoratorInfo *decorator_info;
GFile *file;
+ GCancellable *cancellable;
+ gulong signal_id;
};
struct _TrackerExtractDecoratorPrivate {
@@ -162,6 +164,10 @@ get_metadata_cb (TrackerExtract *extract,
tracker_extract_persistence_remove_file (priv->persistence, data->file);
g_hash_table_remove (priv->recovery_files, tracker_decorator_info_get_url (data->decorator_info));
+ if (data->cancellable && data->signal_id != 0) {
+ g_cancellable_disconnect (data->cancellable, data->signal_id);
+ }
+
if (error) {
decorator_ignore_file (data->file, data->decorator);
tracker_decorator_info_complete_error (data->decorator_info, error);
@@ -208,6 +214,7 @@ get_metadata_cb (TrackerExtract *extract,
tracker_decorator_info_unref (data->decorator_info);
g_object_unref (data->file);
+ g_object_unref (data->cancellable);
g_free (data);
}
@@ -231,6 +238,28 @@ decorator_get_recovery_file (TrackerExtractDecorator *decorator,
return file;
}
+static void
+task_cancellable_cancelled_cb (GCancellable *cancellable,
+ ExtractData *data)
+{
+ TrackerExtractDecoratorPrivate *priv;
+ gchar *uri;
+
+ /* Delete persistence file on cancellation, we don't want to interpret
+ * this as a failed operation.
+ */
+ priv = tracker_extract_decorator_get_instance_private (TRACKER_EXTRACT_DECORATOR (data->decorator));
+ tracker_extract_persistence_remove_file (priv->persistence, data->file);
+ uri = g_file_get_uri (data->file);
+
+ g_message ("Cancelled task for '%s' was currently being "
+ "processed, _exit()ing immediately",
+ uri);
+ g_free (uri);
+
+ _exit (0);
+}
+
static void
decorator_next_item_cb (TrackerDecorator *decorator,
GAsyncResult *result,
@@ -281,6 +310,14 @@ decorator_next_item_cb (TrackerDecorator *decorator,
tracker_extract_persistence_add_file (priv->persistence, data->file);
+ g_set_object (&data->cancellable, g_task_get_cancellable (task));
+
+ if (data->cancellable) {
+ data->signal_id = g_cancellable_connect (data->cancellable,
+ G_CALLBACK (task_cancellable_cancelled_cb),
+ data, NULL);
+ }
+
tracker_extract_file (priv->extractor,
tracker_decorator_info_get_url (info),
tracker_decorator_info_get_mimetype (info),
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 56107f195..12cb00b4f 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -89,7 +89,6 @@ typedef struct {
TrackerExtractMetadataFunc func;
GModule *module;
- guint signal_id;
guint timeout_id;
guint success : 1;
} TrackerExtractTask;
@@ -324,29 +323,6 @@ get_file_metadata (TrackerExtractTask *task,
return task->success;
}
-/* This function is called on the thread calling g_cancellable_cancel() */
-static void
-task_cancellable_cancelled_cb (GCancellable *cancellable,
- TrackerExtractTask *task)
-{
- TrackerExtractPrivate *priv;
- TrackerExtract *extract;
-
- extract = task->extract;
- priv = TRACKER_EXTRACT_GET_PRIVATE (extract);
-
- g_mutex_lock (&priv->task_mutex);
-
- if (g_list_find (priv->running_tasks, task)) {
- g_message ("Cancelled task for '%s' was currently being "
- "processed, _exit()ing immediately",
- task->file);
- _exit (0);
- }
-
- g_mutex_unlock (&priv->task_mutex);
-}
-
static gboolean
task_deadline_cb (gpointer user_data)
{
@@ -414,22 +390,12 @@ extract_task_new (TrackerExtract *extract,
g_source_attach (source, g_task_get_context (G_TASK (task->res)));
}
- if (task->cancellable) {
- task->signal_id = g_cancellable_connect (cancellable,
- G_CALLBACK (task_cancellable_cancelled_cb),
- task, NULL);
- }
-
return task;
}
static void
extract_task_free (TrackerExtractTask *task)
{
- if (task->cancellable && task->signal_id != 0) {
- g_cancellable_disconnect (task->cancellable, task->signal_id);
- }
-
notify_task_finish (task, task->success);
if (task->timeout_id)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]