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



commit 1606a466e30ddab49dae0c33c5b9ce8fdd450ef6
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 `/`.
    
    The motivation for this 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    |   12 +++++++++++-
 2 files changed, 15 insertions(+), 1 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..db212ec 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] == '/') {
+               path = g_strdup(priv->name);
+
+               if (!g_file_test (path, 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;
+               }
+       } else if (priv->name) {
                path = find_rule_in_data_dirs (priv->name);
 
                if (!path) {


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