[tracker-miners/wip/carlosg/cue-file-lookups: 2/5] tracker-extract: Add private API to obtain a readonly connection




commit bdb4a56bbe00e7dbbe00eda0be089a0ffb415f81
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Oct 3 12:22:20 2022 +0200

    tracker-extract: Add private API to obtain a readonly connection
    
    Given the limitations imposed by seccomp, extractor modules cannot
    (and should not) use the DBus connection or a readwrite connection
    where direct updates are possible.
    
    However these may want to inspect data existing in the filesystem
    miner database, provide this API so that extractor modules can obtain
    a readonly connection.

 src/tracker-extract/tracker-main.c | 20 ++++++++++++++++++++
 src/tracker-extract/tracker-main.h |  4 ++++
 2 files changed, 24 insertions(+)
---
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index 9aae5f6fd..75b7acc3d 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -291,6 +291,26 @@ get_cache_dir (TrackerDomainOntology *domain_ontology)
        return g_file_get_child (cache, "files");
 }
 
+TrackerSparqlConnection *
+tracker_main_get_readonly_connection (GError **error)
+{
+       TrackerDomainOntology *domain_ontology = NULL;
+       g_autoptr (GFile) store = NULL;
+
+       domain_ontology = tracker_domain_ontology_new (domain_ontology_name, NULL, error);
+       if (!domain_ontology)
+               return NULL;
+
+       store = get_cache_dir (domain_ontology);
+       tracker_domain_ontology_unref (domain_ontology);
+
+       return tracker_sparql_connection_new (TRACKER_SPARQL_CONNECTION_FLAGS_READONLY,
+                                             store,
+                                             NULL,
+                                             NULL,
+                                             error);
+}
+
 int
 main (int argc, char *argv[])
 {
diff --git a/src/tracker-extract/tracker-main.h b/src/tracker-extract/tracker-main.h
index 4af2e3e06..fdf1ceec0 100644
--- a/src/tracker-extract/tracker-main.h
+++ b/src/tracker-extract/tracker-main.h
@@ -23,11 +23,15 @@
 
 #include "tracker-config.h"
 
+#include <libtracker-sparql/tracker-sparql.h>
+
 G_BEGIN_DECLS
 
 /* Enables getting the config object from extractors */
 TrackerConfig    *tracker_main_get_config         (void);
 
+TrackerSparqlConnection * tracker_main_get_readonly_connection (GError **error);
+
 G_END_DECLS
 
 #endif /* __TRACKER_MAIN_H__ */


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