summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2020-05-11 01:32:49 +0200
committerSam Thursfield <sam@afuera.me.uk>2020-05-11 02:07:36 +0200
commit72ab6fb759e05a1b0a811fdcd22c924f1c84b5b5 (patch)
tree7a89ffe2be9220e14a4cf3d7549eda41bd5fc220
parentf434a61bf523a1ff57b050c9d68fe9342a1fbdc5 (diff)
downloadtracker-72ab6fb759e05a1b0a811fdcd22c924f1c84b5b5.tar.gz
cli: Add `tracker sparql --list-graphs` option
-rw-r--r--docs/manpages/tracker-sparql.1.txt5
-rw-r--r--src/tracker/tracker-sparql.c30
2 files changed, 34 insertions, 1 deletions
diff --git a/docs/manpages/tracker-sparql.1.txt b/docs/manpages/tracker-sparql.1.txt
index 1df1d7200..d943de5dd 100644
--- a/docs/manpages/tracker-sparql.1.txt
+++ b/docs/manpages/tracker-sparql.1.txt
@@ -88,7 +88,10 @@ See also *--tree* and *--query*.
_property_ does not have to be supplied here. This is optional and
filters the results according to any argument supplied. With no
_property_, all properties are listed.
-
+* -g, --list-graphs::
+ List all the named graphs in the database. These are used by the
+ filesystem miner to separate metadata so that apps can only see
+ the information relevant to them.
*-t, --tree=[_class_]*::
Prints a tree showing all parent classes of _class_ in the ontology.
The _class_ can be provided in shorthand or longhand (see
diff --git a/src/tracker/tracker-sparql.c b/src/tracker/tracker-sparql.c
index 736c7581d..ed51640d6 100644
--- a/src/tracker/tracker-sparql.c
+++ b/src/tracker/tracker-sparql.c
@@ -40,6 +40,7 @@
list_properties || \
list_notifies || \
list_indexes || \
+ list_graphs || \
tree || \
search || \
get_shorthand || \
@@ -94,6 +95,7 @@ static gboolean list_class_prefixes;
static gchar *list_properties;
static gchar *list_notifies;
static gchar *list_indexes;
+static gchar *list_graphs;
static gchar *tree;
static gchar *get_shorthand;
static gchar *get_longhand;
@@ -147,6 +149,10 @@ static GOptionEntry entries[] = {
N_("Retrieve indexes used in database to improve performance (PROPERTY is optional)"),
N_("PROPERTY"),
},
+ { "list-graphs", 'g', 0, G_OPTION_ARG_NONE, &list_graphs,
+ N_("Retrieve all named graphs"),
+ NULL,
+ },
{ "tree", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, parse_tree,
N_("Describe subclasses, superclasses (can be used with -s to highlight parts of the tree and -p to show properties)"),
N_("CLASS"),
@@ -1288,6 +1294,30 @@ sparql_run (void)
print_cursor (cursor, _("No indexes were found"), _("Indexes"), TRUE);
}
+ if (list_graphs) {
+ const gchar *query;
+
+ /* First list classes */
+ query = g_strdup_printf ("SELECT DISTINCT ?g "
+ "WHERE {"
+ " GRAPH ?g { ?s ?p ?o }"
+ "}");
+
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
+
+ if (error) {
+ g_printerr ("%s, %s\n",
+ _("Could not list named graphs"),
+ error->message);
+ g_error_free (error);
+ g_object_unref (connection);
+
+ return EXIT_FAILURE;
+ }
+
+ print_cursor (cursor, _("No graphs were found"), _("Named graphs"), TRUE);
+ }
+
if (tree) {
return tree_get (connection, tree, search);
}