[polari/wip/carlosg/tracker: 4/15] lib: Allow to create a readonly connection



commit d02ae194241d3e240d9f83f1a5c576fb411fccb7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Feb 24 22:48:45 2019 +0100

    lib: Allow to create a readonly connection
    
    This at least makes sense for the query tool. Having two readwrite
    processes at the same time is usually a bad idea, this allows for
    doing queries without botching imports.

 src/lib/polari-util.c  | 9 +++++++--
 src/lib/polari-util.h  | 3 ++-
 src/logger.js          | 2 +-
 src/polari-log-tool.c  | 4 ++--
 src/telepathyClient.js | 2 +-
 5 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/src/lib/polari-util.c b/src/lib/polari-util.c
index deb4a80..abf38c9 100644
--- a/src/lib/polari-util.c
+++ b/src/lib/polari-util.c
@@ -140,7 +140,8 @@ polari_util_match_identify_message (const char  *message,
  * Returns: (transfer none):
  */
 TrackerSparqlConnection *
-polari_util_get_tracker_connection (GError **error)
+polari_util_get_tracker_connection (gboolean readonly,
+                                    GError **error)
 {
   static TrackerSparqlConnection *connection = NULL;
 
@@ -148,6 +149,7 @@ polari_util_get_tracker_connection (GError **error)
     {
       g_autoptr(GFile) store, ontology;
       g_autofree char *store_path;
+      TrackerSparqlConnectionFlags flags = 0;
 
       store_path = g_build_filename (g_get_user_data_dir (),
                                      "polari",
@@ -156,7 +158,10 @@ polari_util_get_tracker_connection (GError **error)
       store = g_file_new_for_path (store_path);
       ontology = g_file_new_for_uri ("resource:///org/gnome/Polari/ontologies/");
 
-      connection = tracker_sparql_connection_local_new (TRACKER_SPARQL_CONNECTION_FLAGS_NONE,
+      if (readonly)
+        flags |= TRACKER_SPARQL_CONNECTION_FLAGS_READONLY;
+
+      connection = tracker_sparql_connection_local_new (flags,
                                                         store,
                                                         NULL,
                                                         ontology,
diff --git a/src/lib/polari-util.h b/src/lib/polari-util.h
index b321bb2..6804921 100644
--- a/src/lib/polari-util.h
+++ b/src/lib/polari-util.h
@@ -31,4 +31,5 @@ gboolean polari_util_match_identify_message (const char  *message,
                                              char       **username,
                                              char       **password);
 
-TrackerSparqlConnection *polari_util_get_tracker_connection (GError **error);
+TrackerSparqlConnection *polari_util_get_tracker_connection   (gboolean   readonly,
+                                                               GError   **error);
diff --git a/src/logger.js b/src/logger.js
index 0836355..fd97491 100644
--- a/src/logger.js
+++ b/src/logger.js
@@ -4,7 +4,7 @@ const { Gio, GLib, Polari, Tracker } = imports.gi;
 
 var GenericQuery  = class {
     constructor(limit = -1) {
-        this._connection = Polari.util_get_tracker_connection();
+        this._connection = Polari.util_get_tracker_connection(false);
         this._results = [];
         this._limit = limit;
         this._count = 0;
diff --git a/src/polari-log-tool.c b/src/polari-log-tool.c
index 10f1d92..dfc9a52 100644
--- a/src/polari-log-tool.c
+++ b/src/polari-log-tool.c
@@ -56,7 +56,7 @@ import_ready (GObject      *source,
       goto out;
     }
 
-  connection = polari_util_get_tracker_connection (&error);
+  connection = polari_util_get_tracker_connection (FALSE, &error);
   ns_manager = tracker_sparql_connection_get_namespace_manager (connection);
 
   if (error)
@@ -179,7 +179,7 @@ handle_query (int argc,
   GError *error = NULL;
   char *sparql;
 
-  connection = polari_util_get_tracker_connection (NULL);
+  connection = polari_util_get_tracker_connection (TRUE, NULL);
 
   sparql = argv[1];
 
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index 8fca9ab..0201092 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -594,7 +594,7 @@ class TelepathyClient extends Tp.BaseClient {
     }
 
     _logMessage(tpMessage, channel) {
-        let connection = Polari.util_get_tracker_connection ();
+        let connection = Polari.util_get_tracker_connection (false);
 
         let accountId = channel.connection.get_account().get_path_suffix();
         let isRoom = channel.handle_type == Tp.HandleType.ROOM;


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