diff options
-rw-r--r-- | docs/reference/libtracker-miner/libtracker-miner-sections.txt | 2 | ||||
-rw-r--r-- | examples/libtracker-miner/tracker-main.c | 3 | ||||
-rw-r--r-- | src/libtracker-miner/tracker-miner-fs.c | 148 | ||||
-rw-r--r-- | src/libtracker-miner/tracker-miner-fs.h | 13 | ||||
-rw-r--r-- | src/libtracker-miner/tracker-miner.vapi | 2 | ||||
-rw-r--r-- | src/miners/apps/tracker-miner-applications.c | 32 | ||||
-rw-r--r-- | src/miners/fs/tracker-miner-files.c | 54 |
7 files changed, 105 insertions, 149 deletions
diff --git a/docs/reference/libtracker-miner/libtracker-miner-sections.txt b/docs/reference/libtracker-miner/libtracker-miner-sections.txt index 2a6aabb16..9b23c948f 100644 --- a/docs/reference/libtracker-miner/libtracker-miner-sections.txt +++ b/docs/reference/libtracker-miner/libtracker-miner-sections.txt @@ -202,7 +202,7 @@ tracker_miner_fs_check_directory_with_priority tracker_miner_fs_force_recheck tracker_miner_fs_writeback_file tracker_miner_fs_writeback_notify -tracker_miner_fs_file_notify +tracker_miner_fs_notify_finish tracker_miner_fs_get_urn tracker_miner_fs_get_parent_urn tracker_miner_fs_query_urn diff --git a/examples/libtracker-miner/tracker-main.c b/examples/libtracker-miner/tracker-main.c index e563b8cfc..451967920 100644 --- a/examples/libtracker-miner/tracker-main.c +++ b/examples/libtracker-miner/tracker-main.c @@ -59,6 +59,7 @@ miner_start_cb (gpointer user_data) static gboolean process_file_cb (TrackerMinerFS *fs, GFile *file, + GTask *task, gpointer user_data) { gchar *path; @@ -68,7 +69,7 @@ process_file_cb (TrackerMinerFS *fs, g_free (path); /* Notify that processing is complete. */ - tracker_miner_fs_file_notify (fs, file, NULL); + tracker_miner_fs_notify_finish (fs, task, "", NULL); /* Return FALSE here if you ignored the file. */ return TRUE; diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c index ef5cfd084..bd55a5975 100644 --- a/src/libtracker-miner/tracker-miner-fs.c +++ b/src/libtracker-miner/tracker-miner-fs.c @@ -162,7 +162,6 @@ typedef struct { gchar *parent_urn; gint priority; GCancellable *cancellable; - TrackerSparqlBuilder *builder; TrackerMiner *miner; } UpdateProcessingTaskContext; @@ -453,7 +452,7 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass) * This signal allows both synchronous and asynchronous extraction, * in the synchronous case @cancellable can be safely ignored. In * either case, on successful metadata extraction, implementations - * must call tracker_miner_fs_file_notify() to indicate that + * must call tracker_miner_fs_notify_finish() to indicate that * processing has finished on @file, so the miner can execute * the SPARQL updates and continue processing other files. * @@ -470,7 +469,7 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass) NULL, NULL, NULL, G_TYPE_BOOLEAN, - 3, G_TYPE_FILE, TRACKER_SPARQL_TYPE_BUILDER, G_TYPE_CANCELLABLE); + 2, G_TYPE_FILE, G_TYPE_TASK); /** * TrackerMinerFS::process-file-attributes: @@ -489,7 +488,7 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass) * This signal allows both synchronous and asynchronous extraction, * in the synchronous case @cancellable can be safely ignored. In * either case, on successful metadata extraction, implementations - * must call tracker_miner_fs_file_notify() to indicate that + * must call tracker_miner_fs_notify_finish() to indicate that * processing has finished on @file, so the miner can execute * the SPARQL updates and continue processing other files. * @@ -506,7 +505,7 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass) NULL, NULL, NULL, G_TYPE_BOOLEAN, - 3, G_TYPE_FILE, TRACKER_SPARQL_TYPE_BUILDER, G_TYPE_CANCELLABLE); + 2, G_TYPE_FILE, G_TYPE_TASK); /** * TrackerMinerFS::finished: @@ -1309,8 +1308,7 @@ update_processing_task_context_new (TrackerMiner *miner, gint priority, const gchar *urn, const gchar *parent_urn, - GCancellable *cancellable, - TrackerSparqlBuilder *builder) + GCancellable *cancellable) { UpdateProcessingTaskContext *ctxt; @@ -1324,10 +1322,6 @@ update_processing_task_context_new (TrackerMiner *miner, ctxt->cancellable = g_object_ref (cancellable); } - if (builder) { - ctxt->builder = g_object_ref (builder); - } - return ctxt; } @@ -1341,32 +1335,38 @@ update_processing_task_context_free (UpdateProcessingTaskContext *ctxt) g_object_unref (ctxt->cancellable); } - if (ctxt->builder) { - g_object_unref (ctxt->builder); - } - g_slice_free (UpdateProcessingTaskContext, ctxt); } static void -item_add_or_update_continue (TrackerMinerFS *fs, - TrackerTask *task, - const GError *error) +on_signal_gtask_complete (GObject *source, + GAsyncResult *res, + gpointer user_data) { + TrackerMinerFS *fs = TRACKER_MINER_FS (source); + TrackerTask *task, *sparql_task = NULL; UpdateProcessingTaskContext *ctxt; - TrackerTask *sparql_task = NULL; - GFile *file; - gchar *uri; + GError *error = NULL; + GFile *file = user_data; + gchar *uri, *sparql; + + sparql = g_task_propagate_pointer (G_TASK (res), &error); + g_object_unref (res); + + task = tracker_task_pool_find (fs->priv->task_pool, file); + g_assert (task != NULL); ctxt = tracker_task_get_data (task); - file = tracker_task_get_file (task); uri = g_file_get_uri (file); if (error) { g_message ("Could not process '%s': %s", uri, error->message); + g_error_free (error); fs->priv->total_files_notified_error++; } else { + fs->priv->total_files_notified++; + if (ctxt->urn) { gboolean attribute_update_only; @@ -1382,7 +1382,7 @@ item_add_or_update_continue (TrackerMinerFS *fs, g_debug ("Creating new item '%s'", uri); } - sparql_task = tracker_sparql_task_new_with_sparql (file, ctxt->builder); + sparql_task = tracker_sparql_task_new_take_sparql_str (file, sparql); } if (sparql_task) { @@ -1458,21 +1458,19 @@ item_add_or_update (TrackerMinerFS *fs, gint priority) { TrackerMinerFSPrivate *priv; - TrackerSparqlBuilder *sparql; UpdateProcessingTaskContext *ctxt; GCancellable *cancellable; gboolean processing; - gboolean keep_processing; gboolean attribute_update_only; TrackerTask *task; const gchar *parent_urn, *urn; gchar *uri; GFile *parent; + GTask *gtask; priv = fs->priv; cancellable = g_cancellable_new (); - sparql = tracker_sparql_builder_new_update (); g_object_ref (file); /* Always query. No matter we are notified the file was just @@ -1495,8 +1493,7 @@ item_add_or_update (TrackerMinerFS *fs, priority, urn, parent_urn, - cancellable, - sparql); + cancellable); task = tracker_task_new (file, ctxt, (GDestroyNotify) update_processing_task_context_free); @@ -1508,54 +1505,37 @@ item_add_or_update (TrackerMinerFS *fs, attribute_update_only = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (file), priv->quark_attribute_updated)); + gtask = g_task_new (fs, ctxt->cancellable, on_signal_gtask_complete, file); + if (!attribute_update_only) { g_debug ("Processing file '%s'...", uri); g_signal_emit (fs, signals[PROCESS_FILE], 0, - file, - ctxt->builder, - ctxt->cancellable, + file, gtask, &processing); } else { g_debug ("Processing attributes in file '%s'...", uri); g_signal_emit (fs, signals[PROCESS_FILE_ATTRIBUTES], 0, - file, - ctxt->builder, - ctxt->cancellable, + file, gtask, &processing); } - keep_processing = TRUE; - if (!processing) { - /* Re-fetch data, since it might have been - * removed in broken implementations - */ - task = tracker_task_pool_find (priv->task_pool, file); - - g_message ("%s refused to process '%s'", G_OBJECT_TYPE_NAME (fs), uri); + GError *error; - if (!task) { - g_critical ("%s has returned FALSE in ::process-file for '%s', " - "but it seems that this file has been processed through " - "tracker_miner_fs_file_notify(), this is an " - "implementation error", G_OBJECT_TYPE_NAME (fs), uri); - } else { - tracker_task_pool_remove (priv->task_pool, task); - } + error = g_error_new (tracker_miner_fs_error_quark (), + TRACKER_MINER_FS_ERROR_INIT, + "TrackerMinerFS::%s returned FALSE", + attribute_update_only ? "process-file-attributes" : "process-file"); + g_task_return_error (gtask, error); } else { fs->priv->total_files_processed++; - - if (tracker_task_pool_limit_reached (priv->task_pool)) { - keep_processing = FALSE; - } } g_free (uri); g_object_unref (file); g_object_unref (cancellable); - g_object_unref (sparql); - return keep_processing; + return !tracker_task_pool_limit_reached (priv->task_pool); } static gboolean @@ -3493,55 +3473,35 @@ tracker_miner_fs_check_directory (TrackerMinerFS *fs, } /** - * tracker_miner_fs_file_notify: + * tracker_miner_fs_notify_finish: * @fs: a #TrackerMinerFS - * @file: a #GFile + * @task: a #GTask obtained in a #TrackerMinerFS signal/vmethod + * @sparql: (nullable): Resulting sparql for the given operation, or %NULL if + * there is an error * @error: a #GError with the error that happened during processing, or %NULL. * * Notifies @fs that all processing on @file has been finished, if any error * happened during file data processing, it should be passed in @error, else - * that parameter will contain %NULL to reflect success. + * @sparql should contain correct SPARQL representing the operation in + * particular. * - * Since: 0.8 + * This function is expected to be called in reaction to all #TrackerMinerFS + * signals **/ void -tracker_miner_fs_file_notify (TrackerMinerFS *fs, - GFile *file, - const GError *error) +tracker_miner_fs_notify_finish (TrackerMinerFS *fs, + GTask *task, + const gchar *sparql, + GError *error) { - TrackerTask *task; - g_return_if_fail (TRACKER_IS_MINER_FS (fs)); - g_return_if_fail (G_IS_FILE (file)); - - fs->priv->total_files_notified++; - - task = tracker_task_pool_find (fs->priv->task_pool, file); - - if (!task) { - gchar *uri; - - uri = g_file_get_uri (file); - g_critical ("%s has notified that file '%s' has been processed, " - "but that file was not in the processing queue. " - "This is an implementation error, please ensure that " - "tracker_miner_fs_file_notify() is called on the same " - "GFile that is passed in ::process-file, and that this" - "signal didn't return FALSE for it", - G_OBJECT_TYPE_NAME (fs), uri); - g_free (uri); - - if (item_queue_is_blocked_by_file (fs, file)) { - /* Ensure we don't stall, although this is a very ugly situation */ - g_object_unref (fs->priv->item_queue_blocker); - fs->priv->item_queue_blocker = NULL; - item_queue_handlers_set_up (fs); - } - - return; - } + g_return_if_fail (G_IS_TASK (task)); + g_return_if_fail (sparql || error); - item_add_or_update_continue (fs, task, error); + if (error) + g_task_return_error (task, error); + else + g_task_return_pointer (task, g_strdup (sparql), g_free); } /** diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h index f55a78d7f..953d29a54 100644 --- a/src/libtracker-miner/tracker-miner-fs.h +++ b/src/libtracker-miner/tracker-miner-fs.h @@ -76,8 +76,7 @@ typedef struct { gboolean (* process_file) (TrackerMinerFS *fs, GFile *file, - TrackerSparqlBuilder *builder, - GCancellable *cancellable); + GTask *task); void (* finished) (TrackerMinerFS *fs, gdouble elapsed, gint directories_found, @@ -86,8 +85,7 @@ typedef struct { gint files_ignored); gboolean (* process_file_attributes) (TrackerMinerFS *fs, GFile *file, - TrackerSparqlBuilder *builder, - GCancellable *cancellable); + GTask *task); gboolean (* writeback_file) (TrackerMinerFS *fs, GFile *file, GStrv rdf_types, @@ -185,9 +183,10 @@ void tracker_miner_fs_writeback_file (TrackerMinerFS *f void tracker_miner_fs_writeback_notify (TrackerMinerFS *fs, GFile *file, const GError *error); -void tracker_miner_fs_file_notify (TrackerMinerFS *fs, - GFile *file, - const GError *error); +void tracker_miner_fs_notify_finish (TrackerMinerFS *fs, + GTask *task, + const gchar *sparql, + GError *error); /* URNs */ const gchar *tracker_miner_fs_get_urn (TrackerMinerFS *fs, diff --git a/src/libtracker-miner/tracker-miner.vapi b/src/libtracker-miner/tracker-miner.vapi index 86cd786d6..bc3d75ab7 100644 --- a/src/libtracker-miner/tracker-miner.vapi +++ b/src/libtracker-miner/tracker-miner.vapi @@ -118,7 +118,7 @@ namespace Tracker { public bool directory_remove (GLib.File file); public bool directory_remove_full (GLib.File file); public static GLib.Quark error_quark (); - public void file_notify (GLib.File file, GLib.Error error); + public void notify_finish (GLib.File file, GLib.Task task, string sparql, GLib.Error error); public void force_mtime_checking (GLib.File directory); public void force_recheck (); public unowned Tracker.DataProvider get_data_provider (); diff --git a/src/miners/apps/tracker-miner-applications.c b/src/miners/apps/tracker-miner-applications.c index 6f9260352..348c3e036 100644 --- a/src/miners/apps/tracker-miner-applications.c +++ b/src/miners/apps/tracker-miner-applications.c @@ -38,12 +38,10 @@ static gboolean miner_applications_initable_init (GInitable GError **error); static gboolean miner_applications_process_file (TrackerMinerFS *fs, GFile *file, - TrackerSparqlBuilder *sparql, - GCancellable *cancellable); + GTask *task); static gboolean miner_applications_process_file_attributes (TrackerMinerFS *fs, GFile *file, - TrackerSparqlBuilder *sparql, - GCancellable *cancellable); + GTask *task); static GQuark miner_applications_error_quark = 0; @@ -56,6 +54,7 @@ struct ProcessApplicationData { GCancellable *cancellable; GKeyFile *key_file; gchar *type; + GTask *task; }; static GInitableIface* miner_applications_initable_parent_iface; @@ -830,6 +829,7 @@ process_application_data_free (ProcessApplicationData *data) g_object_unref (data->file); g_object_unref (data->sparql); g_object_unref (data->cancellable); + g_object_unref (data->task); g_free (data->type); if (data->key_file) { @@ -854,9 +854,8 @@ process_file_cb (GObject *object, file_info = g_file_query_info_finish (file, result, &error); if (error) { - tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), file, error); + tracker_miner_fs_notify_finish (TRACKER_MINER_FS (data->miner), data->task, NULL, error); process_application_data_free (data); - g_error_free (error); return; } @@ -882,13 +881,11 @@ process_file_cb (GObject *object, } } - tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, error); + tracker_miner_fs_notify_finish (TRACKER_MINER_FS (data->miner), data->task, + tracker_sparql_builder_get_result (data->sparql), + error); process_application_data_free (data); - if (error) { - g_error_free (error); - } - if (file_info) { g_object_unref (file_info); } @@ -897,17 +894,17 @@ process_file_cb (GObject *object, static gboolean miner_applications_process_file (TrackerMinerFS *fs, GFile *file, - TrackerSparqlBuilder *sparql, - GCancellable *cancellable) + GTask *task) { ProcessApplicationData *data; const gchar *attrs; data = g_slice_new0 (ProcessApplicationData); data->miner = g_object_ref (fs); - data->sparql = g_object_ref (sparql); + data->sparql = tracker_sparql_builder_new_update (); data->file = g_object_ref (file); - data->cancellable = g_object_ref (cancellable); + data->cancellable = g_object_ref (g_task_get_cancellable (task)); + data->task = g_object_ref (task); attrs = G_FILE_ATTRIBUTE_TIME_MODIFIED "," G_FILE_ATTRIBUTE_STANDARD_TYPE; @@ -916,7 +913,7 @@ miner_applications_process_file (TrackerMinerFS *fs, attrs, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, G_PRIORITY_DEFAULT, - cancellable, + data->cancellable, process_file_cb, data); @@ -926,8 +923,7 @@ miner_applications_process_file (TrackerMinerFS *fs, static gboolean miner_applications_process_file_attributes (TrackerMinerFS *fs, GFile *file, - TrackerSparqlBuilder *sparql, - GCancellable *cancellable) + GTask *task) { gchar *uri; diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c index e06f596f3..4bdaf06c1 100644 --- a/src/miners/fs/tracker-miner-files.c +++ b/src/miners/fs/tracker-miner-files.c @@ -66,6 +66,7 @@ struct ProcessFileData { GCancellable *cancellable; GFile *file; gchar *mime_type; + GTask *task; }; struct TrackerMinerFilesPrivate { @@ -174,12 +175,10 @@ static void index_volumes_changed_cb (GObject *g gpointer user_data); static gboolean miner_files_process_file (TrackerMinerFS *fs, GFile *file, - TrackerSparqlBuilder *sparql, - GCancellable *cancellable); + GTask *task); static gboolean miner_files_process_file_attributes (TrackerMinerFS *fs, GFile *file, - TrackerSparqlBuilder *sparql, - GCancellable *cancellable); + GTask *task); static void miner_files_finished (TrackerMinerFS *fs, gdouble elapsed, gint directories_found, @@ -2014,6 +2013,7 @@ process_file_data_free (ProcessFileData *data) g_object_unref (data->sparql); g_object_unref (data->cancellable); g_object_unref (data->file); + g_object_unref (data->task); g_free (data->mime_type); g_slice_free (ProcessFileData, data); } @@ -2128,11 +2128,9 @@ process_file_cb (GObject *object, if (error) { /* Something bad happened, notify about the error */ - tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), file, error); + tracker_miner_fs_notify_finish (TRACKER_MINER_FS (data->miner), data->task, NULL, error); priv->extraction_queue = g_list_remove (priv->extraction_queue, data); process_file_data_free (data); - g_error_free (error); - return; } @@ -2237,7 +2235,9 @@ process_file_cb (GObject *object, miner_files_add_rdf_types (sparql, file, mime_type); sparql_builder_finish (data, NULL, NULL, NULL, NULL); - tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, NULL); + tracker_miner_fs_notify_finish (TRACKER_MINER_FS (data->miner), data->task, + tracker_sparql_builder_get_result (sparql), + NULL); priv->extraction_queue = g_list_remove (priv->extraction_queue, data); process_file_data_free (data); @@ -2247,10 +2247,9 @@ process_file_cb (GObject *object, } static gboolean -miner_files_process_file (TrackerMinerFS *fs, - GFile *file, - TrackerSparqlBuilder *sparql, - GCancellable *cancellable) +miner_files_process_file (TrackerMinerFS *fs, + GFile *file, + GTask *task) { TrackerMinerFilesPrivate *priv; ProcessFileData *data; @@ -2258,9 +2257,10 @@ miner_files_process_file (TrackerMinerFS *fs, data = g_slice_new0 (ProcessFileData); data->miner = g_object_ref (fs); - data->cancellable = g_object_ref (cancellable); - data->sparql = g_object_ref (sparql); + data->cancellable = g_object_ref (g_task_get_cancellable (task)); + data->sparql = tracker_sparql_builder_new_update (); data->file = g_object_ref (file); + data->task = g_object_ref (task); priv = TRACKER_MINER_FILES (fs)->private; priv->extraction_queue = g_list_prepend (priv->extraction_queue, data); @@ -2276,7 +2276,7 @@ miner_files_process_file (TrackerMinerFS *fs, attrs, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, G_PRIORITY_DEFAULT, - cancellable, + data->cancellable, process_file_cb, data); @@ -2305,9 +2305,8 @@ process_file_attributes_cb (GObject *object, if (error) { /* Something bad happened, notify about the error */ - tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), file, error); + tracker_miner_fs_notify_finish (TRACKER_MINER_FS (data->miner), data->task, NULL, error); process_file_data_free (data); - g_error_free (error); return; } @@ -2320,9 +2319,8 @@ process_file_attributes_cb (GObject *object, 0, "Received request to update attributes but no IRI available!"); /* Notify about the error */ - tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), file, error); + tracker_miner_fs_notify_finish (TRACKER_MINER_FS (data->miner), data->task, NULL, error); process_file_data_free (data); - g_error_free (error); return; } @@ -2382,25 +2380,27 @@ process_file_attributes_cb (GObject *object, g_free (uri); /* Notify about the success */ - tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, NULL); + tracker_miner_fs_notify_finish (TRACKER_MINER_FS (data->miner), data->task, + tracker_sparql_builder_get_result (sparql), + NULL); process_file_data_free (data); } static gboolean -miner_files_process_file_attributes (TrackerMinerFS *fs, - GFile *file, - TrackerSparqlBuilder *sparql, - GCancellable *cancellable) +miner_files_process_file_attributes (TrackerMinerFS *fs, + GFile *file, + GTask *task) { ProcessFileData *data; const gchar *attrs; data = g_slice_new0 (ProcessFileData); data->miner = g_object_ref (fs); - data->cancellable = g_object_ref (cancellable); - data->sparql = g_object_ref (sparql); + data->cancellable = g_object_ref (g_task_get_cancellable (task)); + data->sparql = tracker_sparql_builder_new_update (); data->file = g_object_ref (file); + data->task = g_object_ref (task); /* Query only attributes that may change in an ATTRIBUTES_UPDATED event */ attrs = G_FILE_ATTRIBUTE_TIME_MODIFIED "," @@ -2410,7 +2410,7 @@ miner_files_process_file_attributes (TrackerMinerFS *fs, attrs, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, G_PRIORITY_DEFAULT, - cancellable, + data->cancellable, process_file_attributes_cb, data); |