[tracker/sam/app-domains: 2/2] Allow passing a full path to a domain rule



commit 05d83fe8368e7d0d8002dccdd37f5eda21b529ce
Author: Sam Thursfield <sam afuera me uk>
Date:   Fri Apr 20 22:12:11 2018 +0200

    Allow passing a full path to a domain rule
    
    This extends the TrackerDomainOntology class to handle domain rules
    which are not installed into Tracker's configured prefix. The domain
    name is now interpreted as a full path if the first character is `/`.
    
    Some code was using the input domain rule to determine the name of the
    domain. This breaks when the input domain rule is a full path. The
    domain rule contains the domain name, so this isn't a problem but in
    order to make things work I had to change the behaviour of
    tracker_domain_ontology_get_domain() as previously it would append
    ".Tracker1" onto whatever the domain rule told us the name of the
    domain was. Now it does not do that, so it can be used to get the
    name of the domain itself as well as the names that the Tracker daemons
    running inside that domain should use.
    
    The motivation for this change is that it allows unprivileged users to
    make use of the domain ontologies feature. Previously it could only be
    used by those who had permissions to install the .rule file into /usr.
    
    Some extra work is still needed to make the feature easy to use for
    unpriviliged users, as there also need to be D-Bus service files
    created for the domain. This can be done as an unpriviliged user by
    starting a separate D-Bus instance and looks for .service files in
    a different place, but it's not ideal to require that effort.

 docs/reference/libtracker-sparql/private-store.xml |    4 ++++
 src/libtracker-common/tracker-domain-ontology.c    |   16 +++++++++++++---
 src/libtracker-control/tracker-miner-manager.c     |   10 +++++++---
 src/libtracker-sparql-backend/tracker-backend.vala |    4 ++--
 src/libtracker-sparql/tracker-notifier.c           |    2 +-
 src/tracker-store/tracker-main.vala                |    4 ++--
 6 files changed, 29 insertions(+), 11 deletions(-)
---
diff --git a/docs/reference/libtracker-sparql/private-store.xml 
b/docs/reference/libtracker-sparql/private-store.xml
index 6fe5872..c598173 100644
--- a/docs/reference/libtracker-sparql/private-store.xml
+++ b/docs/reference/libtracker-sparql/private-store.xml
@@ -75,6 +75,10 @@ Miners=Miner.Files;Miner.Extract;
     <programlisting>
 tracker_sparql_connection_set_domain ("org.example.App");
     </programlisting>
+    <para>
+      It is also possible to pass a full path to the domain rule. If the first
+      character of the domain name is / it will be treated as a full path.
+    </para>
   </chapter>
   <chapter id="recommendations">
     <title>Additional precautions and recommendations</title>
diff --git a/src/libtracker-common/tracker-domain-ontology.c b/src/libtracker-common/tracker-domain-ontology.c
index 248cd7b..870f2bc 100644
--- a/src/libtracker-common/tracker-domain-ontology.c
+++ b/src/libtracker-common/tracker-domain-ontology.c
@@ -302,7 +302,17 @@ tracker_domain_ontology_initable_init (GInitable     *initable,
        domain_ontology = TRACKER_DOMAIN_ONTOLOGY (initable);
        priv = tracker_domain_ontology_get_instance_private (domain_ontology);
 
-       if (priv->name) {
+       if (priv->name && priv->name[0] == '/') {
+               if (!g_file_test (priv->name, G_FILE_TEST_IS_REGULAR)) {
+                       inner_error = g_error_new (G_KEY_FILE_ERROR,
+                                                  G_KEY_FILE_ERROR_NOT_FOUND,
+                                                  "Could not find rule at '%s'",
+                                                  priv->name);
+                       goto end;
+               }
+
+               path = g_strdup (priv->name);
+       } else if (priv->name) {
                path = find_rule_in_data_dirs (priv->name);
 
                if (!path) {
@@ -448,9 +458,9 @@ tracker_domain_ontology_get_domain (TrackerDomainOntology *domain_ontology,
 
        priv = tracker_domain_ontology_get_instance_private (domain_ontology);
        if (suffix)
-               return g_strconcat (priv->domain, ".Tracker1.", suffix, NULL);
+               return g_strconcat (priv->domain, ".", suffix, NULL);
        else
-               return g_strconcat (priv->domain, ".Tracker1", NULL);
+               return g_strconcat (priv->domain, NULL);
 }
 
 gboolean
diff --git a/src/libtracker-control/tracker-miner-manager.c b/src/libtracker-control/tracker-miner-manager.c
index 59e222f..84bb154 100644
--- a/src/libtracker-control/tracker-miner-manager.c
+++ b/src/libtracker-control/tracker-miner-manager.c
@@ -696,7 +696,7 @@ tracker_miner_manager_get_running (TrackerMinerManager *manager)
                return NULL;
        }
 
-       prefix = tracker_domain_ontology_get_domain (priv->domain_ontology, "Miner");
+       prefix = tracker_domain_ontology_get_domain (priv->domain_ontology, "Tracker1.Miner");
 
        g_variant_get (v, "(as)", &iter);
        while (g_variant_iter_loop (iter, "&s", &str)) {
@@ -723,7 +723,7 @@ check_file (GFile    *file,
        TrackerMinerManager *manager;
        TrackerMinerManagerPrivate *priv;
        GKeyFile *key_file;
-       gchar *path, *dbus_path, *display_name, *name_suffix, *description;
+       gchar *path, *dbus_path, *display_name, *name_suffix, *full_name_suffix, *description;
        GError *error = NULL;
        MinerData *data;
 
@@ -768,8 +768,12 @@ check_file (GFile    *file,
        data = g_slice_new0 (MinerData);
        data->dbus_path = dbus_path;
        data->name_suffix = name_suffix;
+
+       full_name_suffix = g_strconcat ("Tracker1.", name_suffix, NULL);
        data->dbus_name = tracker_domain_ontology_get_domain (priv->domain_ontology,
-                                                             name_suffix);
+                                                             full_name_suffix);
+       g_free (full_name_suffix);
+
        data->display_name = display_name;
        data->description = description;    /* In .desktop file as _comment */
 
diff --git a/src/libtracker-sparql-backend/tracker-backend.vala 
b/src/libtracker-sparql-backend/tracker-backend.vala
index da96f9e..61dfa97 100644
--- a/src/libtracker-sparql-backend/tracker-backend.vala
+++ b/src/libtracker-sparql-backend/tracker-backend.vala
@@ -193,7 +193,7 @@ class Tracker.Sparql.Backend : Connection {
 
                switch (backend) {
                case Backend.AUTO:
-                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain (), 
global_dbus_connection);
+                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ("Tracker1"), 
global_dbus_connection);
 
                        try {
                                direct = create_readonly_direct ();
@@ -208,7 +208,7 @@ class Tracker.Sparql.Backend : Connection {
                        break;
 
                case Backend.BUS:
-                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain (), 
global_dbus_connection);
+                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ("Tracker1"), 
global_dbus_connection);
                        break;
 
                default:
diff --git a/src/libtracker-sparql/tracker-notifier.c b/src/libtracker-sparql/tracker-notifier.c
index 8f9d65c..23ed5ef 100644
--- a/src/libtracker-sparql/tracker-notifier.c
+++ b/src/libtracker-sparql/tracker-notifier.c
@@ -715,7 +715,7 @@ tracker_notifier_initable_init (GInitable     *initable,
        if (!domain_ontology)
                return FALSE;
 
-       dbus_name = tracker_domain_ontology_get_domain (domain_ontology, NULL);
+       dbus_name = tracker_domain_ontology_get_domain (domain_ontology, "Tracker1");
 
        priv->has_arg0_filter =
                priv->expanded_classes && g_strv_length (priv->expanded_classes) == 1;
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index 8e6d889..292cc35 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -235,7 +235,7 @@ License which can be viewed at:
                cache_location = domain_ontology_config.get_cache ();
                data_location = domain_ontology_config.get_journal ();
                ontology_location = domain_ontology_config.get_ontology ();
-               domain = domain_ontology_config.get_domain ();
+               domain = domain_ontology_config.get_domain ("Tracker1");
 
                sanity_check_option_values (config);
 
@@ -333,7 +333,7 @@ License which can be viewed at:
                        main_loop = new MainLoop ();
 
                        if (domain != null)
-                               Tracker.DBus.watch_domain (domain_ontology, main_loop);
+                               Tracker.DBus.watch_domain (domain_ontology_config.get_domain(), main_loop);
 
                        initialize_signal_handler ();
 


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