[tracker-miners/wip/carlosg/cli-improvements: 11/30] miners: Use error reporting infrastructure




commit dbe4faf2a8470f45f22f0cd3b9153ddc3df9c2aa
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Aug 16 15:23:52 2020 +0200

    miners: Use error reporting infrastructure
    
    Adapt both tracker-miner-fs and tracker-extract to store errors in
    a location at ~/.cache. These errors can be then read eg. via CLI.

 src/libtracker-miner/tracker-decorator.c        | 79 +++++++++----------------
 src/libtracker-miner/tracker-miner-fs.c         |  8 ++-
 src/libtracker-miner/tracker-sparql-buffer.c    | 10 ++++
 src/libtracker-miner/tracker-sparql-buffer.h    |  1 +
 src/miners/fs/tracker-main.c                    |  6 ++
 src/tracker-extract/tracker-extract-decorator.c |  2 +
 src/tracker-extract/tracker-extract.c           |  2 -
 src/tracker-extract/tracker-main.c              | 14 +++++
 8 files changed, 67 insertions(+), 55 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-decorator.c b/src/libtracker-miner/tracker-decorator.c
index b5ec646b8..685dfaaad 100644
--- a/src/libtracker-miner/tracker-decorator.c
+++ b/src/libtracker-miner/tracker-decorator.c
@@ -21,7 +21,7 @@
 
 #include <string.h>
 
-#include <libtracker-miners-common/tracker-debug.h>
+#include <libtracker-miners-common/tracker-common.h>
 
 #include "tracker-decorator.h"
 #include "tracker-priority-queue.h"
@@ -60,7 +60,7 @@ struct _TrackerDecoratorInfo {
 
 struct _SparqlUpdate {
        gchar *sparql;
-       gint id;
+       gchar *url;
 };
 
 struct _TrackerDecoratorPrivate {
@@ -241,52 +241,6 @@ decorator_update_state (TrackerDecorator *decorator,
                g_object_set (decorator, "status", message, NULL);
 }
 
-static void
-item_warn (TrackerSparqlConnection *conn,
-           gint                     id,
-           const gchar             *sparql,
-           const GError            *error)
-{
-       TrackerSparqlCursor *cursor;
-       const gchar *elem;
-       gchar *query;
-
-       query = g_strdup_printf ("SELECT COALESCE (nie:url (?u), ?u) {"
-                                "  ?u a rdfs:Resource. "
-                                "  FILTER (tracker:id (?u) = %d)"
-                                "}", id);
-
-       cursor = tracker_sparql_connection_query (conn, query, NULL, NULL);
-       g_free (query);
-
-       g_debug ("--8<------------------------------");
-       g_debug ("The information relevant for a bug report is between "
-                "the dotted lines");
-
-       if (cursor &&
-           tracker_sparql_cursor_next (cursor, NULL, NULL)) {
-               elem = tracker_sparql_cursor_get_string (cursor, 0, NULL);
-               g_warning ("Could not insert metadata for item \"%s\": %s",
-                          elem, error->message);
-       } else {
-               g_warning ("Could not insert metadata for item with ID %d: %s",
-                          id, error->message);
-       }
-
-       g_warning ("If the error above is recurrent for the same item/ID, "
-                  "consider running \"%s\" in the terminal with the "
-                  "G_MESSAGES_DEBUG=Tracker environment variable, and filing a "
-                  "bug with the additional information", g_get_prgname ());
-
-       g_debug ("Sparql was:\n%s", sparql);
-       g_debug ("NOTE: The information above may contain data you "
-                "consider sensitive. Feel free to edit it out, but please "
-                "keep it as unmodified as you possibly can.");
-       g_debug ("------------------------------>8--");
-
-       g_clear_object (&cursor);
-}
-
 static void
 retry_synchronously (TrackerDecorator *decorator,
                      GArray           *commit_buffer)
@@ -307,11 +261,33 @@ retry_synchronously (TrackerDecorator *decorator,
                                                  &error);
 
                if (error) {
-                       item_warn (sparql_conn, update->id, update->sparql, error);
+                       GFile *file = g_file_new_for_uri (update->url);
+
+                       tracker_error_report (file, error->message, update->sparql);
+                       g_error_free (error);
+                       g_object_unref (file);
                }
        }
 }
 
+static void
+tag_success (TrackerDecorator *decorator,
+             GArray           *commit_buffer)
+{
+       guint i;
+
+       for (i = 0; i < commit_buffer->len; i++) {
+               SparqlUpdate *update;
+               GFile *file;
+
+               update = &g_array_index (commit_buffer, SparqlUpdate, i);
+
+               file = g_file_new_for_uri (update->url);
+               tracker_error_report_delete (file);
+               g_object_unref (file);
+       }
+}
+
 static void
 decorator_commit_cb (GObject      *object,
                      GAsyncResult *result,
@@ -330,6 +306,8 @@ decorator_commit_cb (GObject      *object,
        if (!tracker_sparql_connection_update_array_finish (conn, result, NULL)) {
                g_debug ("SPARQL error detected in batch, retrying one by one");
                retry_synchronously (decorator, priv->commit_buffer);
+       } else {
+               tag_success (decorator, priv->commit_buffer);
        }
 
        g_clear_pointer (&priv->commit_buffer, g_array_unref);
@@ -341,6 +319,7 @@ decorator_commit_cb (GObject      *object,
 static void
 sparql_update_clear (SparqlUpdate *update)
 {
+       g_free (update->url);
        g_free (update->sparql);
 }
 
@@ -506,7 +485,7 @@ decorator_task_done (GObject      *object,
 
                /* Add resulting sparql to buffer and check whether flushing */
                update.sparql = sparql;
-               update.id = info->id;
+               update.url = g_strdup (info->url);
 
                if (!priv->sparql_buffer)
                        priv->sparql_buffer = sparql_buffer_new ();
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 349476c10..9e0e05389 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1180,15 +1180,17 @@ sparql_buffer_task_finished_cb (GObject      *object,
 
        task = tracker_sparql_buffer_push_finish (TRACKER_SPARQL_BUFFER (object),
                                                  result, &error);
+       task_file = tracker_task_get_file (task);
 
        if (error) {
-               g_critical ("Could not execute sparql: %s", error->message);
+               g_warning ("Could not execute sparql: %s", error->message);
+               tracker_error_report (task_file, error->message,
+                                     tracker_sparql_task_get_sparql (task));
                priv->total_files_notified_error++;
                g_error_free (error);
        }
 
-       task_file = tracker_task_get_file (task);
-
+       tracker_error_report_delete (task_file);
        recursive = GPOINTER_TO_INT (g_object_steal_qdata (G_OBJECT (task_file),
                                                             priv->quark_recursive_removal));
        tracker_file_notifier_invalidate_file_iri (priv->file_notifier, task_file, recursive);
diff --git a/src/libtracker-miner/tracker-sparql-buffer.c b/src/libtracker-miner/tracker-sparql-buffer.c
index aac5c18bb..d5a538d41 100644
--- a/src/libtracker-miner/tracker-sparql-buffer.c
+++ b/src/libtracker-miner/tracker-sparql-buffer.c
@@ -498,6 +498,16 @@ tracker_sparql_task_new_with_sparql_str (GFile       *file,
                                 (GDestroyNotify) sparql_task_data_free);
 }
 
+const gchar *
+tracker_sparql_task_get_sparql (TrackerTask *task)
+{
+       SparqlTaskData *task_data;
+
+       task_data = tracker_task_get_data (task);
+
+       return task_data->str;
+}
+
 TrackerTask *
 tracker_sparql_buffer_push_finish (TrackerSparqlBuffer  *buffer,
                                    GAsyncResult         *res,
diff --git a/src/libtracker-miner/tracker-sparql-buffer.h b/src/libtracker-miner/tracker-sparql-buffer.h
index 87b2b0144..e7d4a2b4a 100644
--- a/src/libtracker-miner/tracker-sparql-buffer.h
+++ b/src/libtracker-miner/tracker-sparql-buffer.h
@@ -84,6 +84,7 @@ TrackerTask *        tracker_sparql_task_new_take_sparql_str (GFile
                                                               gchar                *sparql_str);
 TrackerTask *        tracker_sparql_task_new_with_sparql_str (GFile                *file,
                                                               const gchar          *sparql_str);
+const gchar *        tracker_sparql_task_get_sparql          (TrackerTask *task);
 
 G_END_DECLS
 
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 24255b058..292428e54 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -1024,6 +1024,12 @@ main (gint argc, gchar *argv[])
                              no_daemon ? "No" : "Yes",
                              no_daemon ? "(forced by command line)" : ""));
 
+       if (!dry_run) {
+               GFile *store = get_cache_dir (domain_ontology);
+               tracker_error_report_init (store);
+               g_object_unref (store);
+       }
+
        if (!setup_connection_and_endpoint (domain_ontology,
                                            connection,
                                            &sparql_conn,
diff --git a/src/tracker-extract/tracker-extract-decorator.c b/src/tracker-extract/tracker-extract-decorator.c
index cfbb3ae42..84451fc8f 100644
--- a/src/tracker-extract/tracker-extract-decorator.c
+++ b/src/tracker-extract/tracker-extract-decorator.c
@@ -438,6 +438,8 @@ decorator_ignore_file (GFile    *file,
                return;
        }
 
+       tracker_error_report (file, "Crash/hang handling file", NULL);
+
        mimetype = g_file_info_get_attribute_string (info,
                                                     G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
        hash = tracker_extract_module_manager_get_hash (mimetype);
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 12cb00b4f..e19bc0b40 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -331,8 +331,6 @@ task_deadline_cb (gpointer user_data)
        g_warning ("File '%s' took too long to process. Shutting down everything",
                   task->file);
 
-       if (task->cancellable)
-               g_cancellable_cancel (task->cancellable);
        _exit (0);
 }
 
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index c0ed1ec23..72c79fd5b 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -274,6 +274,15 @@ on_decorator_finished (TrackerDecorator *decorator,
                                                     main_loop);
 }
 
+static GFile *
+get_cache_dir (TrackerDomainOntology *domain_ontology)
+{
+       GFile *cache;
+
+       cache = tracker_domain_ontology_get_cache (domain_ontology);
+       return g_file_get_child (cache, "files");
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -288,6 +297,7 @@ main (int argc, char *argv[])
        TrackerSparqlConnection *sparql_connection;
        TrackerDomainOntology *domain_ontology;
        gchar *domain_name, *dbus_name;
+       GFile *cache_dir;
 
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -350,6 +360,10 @@ main (int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
+       cache_dir = get_cache_dir (domain_ontology);
+       tracker_error_report_init (cache_dir);
+       g_object_unref (cache_dir);
+
        config = tracker_config_new ();
 
        /* Extractor command line arguments */


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