[tracker/sam/info-fix] cli: Fix breakage in `tracker info`



commit 51d11e24bb42d4264ab45ba94085b008b6a88905
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Feb 24 22:47:25 2020 +0100

    cli: Fix breakage in `tracker info`
    
    We call tracker_sparql_get_prefixes() from `tracker info`. The
    function tries to use the CLI args from tracker-sparql.c which are
    uninitialized in this case, leading to spurious "Specify one --database,
    --dbus-service or --remote-service option" errors.

 src/tracker/tracker-info.c   |  2 +-
 src/tracker/tracker-sparql.c | 23 +++++------------------
 src/tracker/tracker-sparql.h |  2 +-
 3 files changed, 7 insertions(+), 20 deletions(-)
---
diff --git a/src/tracker/tracker-info.c b/src/tracker/tracker-info.c
index 7c94cc90b..169d26413 100644
--- a/src/tracker/tracker-info.c
+++ b/src/tracker/tracker-info.c
@@ -312,7 +312,7 @@ info_run (void)
                return EXIT_FAILURE;
        }
 
-       prefixes = tracker_sparql_get_prefixes ();
+       prefixes = tracker_sparql_get_prefixes (connection);
 
        /* print all prefixes if using turtle format and not showing full namespaces */
        if (turtle && !full_namespaces) {
diff --git a/src/tracker/tracker-sparql.c b/src/tracker/tracker-sparql.c
index 94923deed..f1c892abe 100644
--- a/src/tracker/tracker-sparql.c
+++ b/src/tracker/tracker-sparql.c
@@ -193,24 +193,13 @@ create_connection (GError **error)
 }
 
 GHashTable *
-tracker_sparql_get_prefixes (void)
+tracker_sparql_get_prefixes (TrackerSparqlConnection *connection)
 {
-       TrackerSparqlConnection *connection;
        TrackerSparqlCursor *cursor;
        GError *error = NULL;
        GHashTable *retval;
        const gchar *query;
 
-       connection = create_connection (&error);
-
-       if (!connection) {
-               g_printerr ("%s: %s\n",
-                           _("Could not establish a connection to Tracker"),
-                           error ? error->message : _("No error given"));
-               g_clear_error (&error);
-               return NULL;
-       }
-
        retval = g_hash_table_new_full (g_str_hash,
                                        g_str_equal,
                                        g_free,
@@ -229,8 +218,6 @@ tracker_sparql_get_prefixes (void)
 
        cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
 
-       g_object_unref (connection);
-
        if (error) {
                g_printerr ("%s, %s\n",
                            _("Unable to retrieve namespace prefixes"),
@@ -981,7 +968,7 @@ tree_get (TrackerSparqlConnection *connection,
        root = tree_new ();
 
        /* Get shorthand prefixes for printing / filtering */
-       prefixes = tracker_sparql_get_prefixes ();
+       prefixes = tracker_sparql_get_prefixes (connection);
 
        /* Is class_lookup a shothand string, e.g. nfo:FileDataObject? */
        if (class_lookup && *class_lookup && strchr (class_lookup, ':')) {
@@ -1355,7 +1342,7 @@ sparql_run (void)
        }
 
        if (get_shorthand) {
-               GHashTable *prefixes = tracker_sparql_get_prefixes ();
+               GHashTable *prefixes = tracker_sparql_get_prefixes (connection);
                gchar *result;
 
                result = tracker_sparql_get_shorthand (prefixes, get_shorthand);
@@ -1368,7 +1355,7 @@ sparql_run (void)
        }
 
        if (get_longhand) {
-               GHashTable *prefixes = tracker_sparql_get_prefixes ();
+               GHashTable *prefixes = tracker_sparql_get_prefixes (connection);
                gchar *result;
 
                result = tracker_sparql_get_longhand (prefixes, get_longhand);
@@ -1459,7 +1446,7 @@ sparql_run (void)
                        GHashTable *prefixes = NULL;
 
                        if (strstr (query, "fts:offsets")) {
-                               prefixes = tracker_sparql_get_prefixes ();
+                               prefixes = tracker_sparql_get_prefixes (connection);
                        }
 
                        cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
diff --git a/src/tracker/tracker-sparql.h b/src/tracker/tracker-sparql.h
index c8601dd8b..c5a03a8e0 100644
--- a/src/tracker/tracker-sparql.h
+++ b/src/tracker/tracker-sparql.h
@@ -27,7 +27,7 @@
 int         tracker_sparql               (int                       argc,
                                           const char              **argv);
 
-GHashTable *tracker_sparql_get_prefixes  (void);
+GHashTable *tracker_sparql_get_prefixes  (TrackerSparqlConnection  *connection);
 gchar *     tracker_sparql_get_longhand  (GHashTable               *prefixes,
                                           const gchar              *shorthand);
 gchar *     tracker_sparql_get_shorthand (GHashTable               *prefixes,


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