[tracker] libtracker-direct: don't allow connection if current and db locale mismatch



commit fa6317fbabb1a75be6830fa6e9472805464d62cd
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Fri Oct 11 10:28:00 2013 +0200

    libtracker-direct: don't allow connection if current and db locale mismatch
    
    If the tracker-store (and therefore the database) are using a specific locale,
    we need to make sure that any process accessing the database with direct access
    also uses the same locale, or it won't get any results.
    
    So, once we find that the current and db locales are different, we just fail
    the creation of the Tracker.Direct.Connection, and the application will
    automatically fallback to using the Tracker.Bus.Connection.
    
    E.g. with tracker-store running with en_US.utf8, if we use a query with the same
    locale, it goes ok:
      $ LC_COLLATE=en_US.utf8 tracker-sparql -q 'SELECT ?u { ?u nie:url "file:///home/something.png" }'
      Results:
        urn:uuid:9e75e781-88b7-96bb-a3cf-b2ae77d4d735
    
    Without this patch, if not using the same locale, we would have:
      $ LC_COLLATE=C tracker-sparql -q 'SELECT ?u { ?u nie:url "file:///home/something.png" }'
      Results:
        None
    
    And with this patch in, we'll fallback to the bus connection, yielding the correct results:
      $ LC_COLLATE=C tracker-sparql -q 'SELECT ?u { ?u nie:url "file:///home/something.png" }'
      Results:
        urn:uuid:9e75e781-88b7-96bb-a3cf-b2ae77d4d735
    
    Note that if we force using the direct connection, it will fail:
      $ TRACKER_SPARQL_BACKEND=direct LC_COLLATE=C tracker-sparql -q 'SELECT ?u { ?u nie:url 
"file:///home/something.png" }'
      Could not establish a connection to Tracker: Locale mismatch, cannot use direct connection
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676209

 src/libtracker-common/libtracker-common.vapi |    5 +++++
 src/libtracker-data/libtracker-data.vapi     |    1 +
 src/libtracker-direct/tracker-direct.vala    |    7 +++++++
 3 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-common/libtracker-common.vapi b/src/libtracker-common/libtracker-common.vapi
index 4f38dbe..0475fbe 100644
--- a/src/libtracker-common/libtracker-common.vapi
+++ b/src/libtracker-common/libtracker-common.vapi
@@ -65,6 +65,11 @@ namespace Tracker {
                public void shutdown ();
        }
 
+       [CCode (cheader_filename = "libtracker-common/tracker-locale.h")]
+       namespace Locale {
+               public void init ();
+       }
+
        [Compact]
        [CCode (ref_function = "", unref_function = "", cheader_filename = 
"libtracker-common/tracker-common.h")]
        public class DBusRequest {
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index d50779e..65ca605 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -87,6 +87,7 @@ namespace Tracker {
                public void lock ();
                public bool trylock ();
                public void unlock ();
+               public bool locale_changed ();
        }
 
        [CCode (cheader_filename = "libtracker-data/tracker-db-interface.h")]
diff --git a/src/libtracker-direct/tracker-direct.vala b/src/libtracker-direct/tracker-direct.vala
index 2480848..c5f6d70 100644
--- a/src/libtracker-direct/tracker-direct.vala
+++ b/src/libtracker-direct/tracker-direct.vala
@@ -26,6 +26,13 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
 
                try {
                        if (use_count == 0) {
+                               // make sure that current locale vs db locale are the same,
+                               // otherwise return an error
+                               Locale.init ();
+                               if (DBManager.locale_changed ()) {
+                                       throw new Sparql.Error.INTERNAL ("Locale mismatch, cannot use direct 
connection");
+                               }
+
                                uint select_cache_size = 100;
                                string env_cache_size = Environment.get_variable 
("TRACKER_SPARQL_CACHE_SIZE");
 


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