[tracker/wip/carlosg/service-fixes: 2/8] libtracker-data: Use md5 to uniquify graph in-memory databases



commit 4a8d6c0a6935665b9421ee6ee8dedf812a701ab3
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jun 8 16:26:35 2020 +0200

    libtracker-data: Use md5 to uniquify graph in-memory databases
    
    If a database is opened in memory, new graphs would be created as
    further in-memory databases, however there is a clash with our
    default graph naming scheme. The "tracker:" prefix expands to
    "https://tracker.api.gnome.org/...#"; and further characters of
    the file name after that '#' are ignored. This makes all our
    "tracker:*" graphs resolve to the same in-memory database, causing
    glitches and warnings.
    
    Get a md5 out of the graph name, so it's unique enough, and free
    of troublesome characters. This makes the different graphs resolve
    to separate in-memory databases and everything work again.
    
    Could be seen with eg:
    $ tracker3 endpoint -b org.foo.Bar -o nepomuk
    $ tracker3 sparql -b org.foo.Bar -u -q "CREATE GRAPH tracker:Yay"
    $ tracker3 sparql -b org.foo.Bar -u -q "CREATE GRAPH tracker:Ouch"

 src/libtracker-data/tracker-db-interface-sqlite.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c 
b/src/libtracker-data/tracker-db-interface-sqlite.c
index ff3332367..d357e1018 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -3643,9 +3643,12 @@ tracker_db_interface_attach_database (TrackerDBInterface  *db_interface,
                uri = g_file_get_path (file);
        } else if (db_interface->shared_cache_key &&
                   (db_interface->flags & TRACKER_DB_INTERFACE_IN_MEMORY) != 0) {
+               gchar *md5;
+
+               md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, name, -1);
                uri = g_strdup_printf ("file:%s-%s?mode=memory&cache=shared",
-                                       db_interface->shared_cache_key,
-                                       name);
+                                      db_interface->shared_cache_key, md5);
+               g_free (md5);
        }
 
        sql = g_strdup_printf ("ATTACH DATABASE \"%s\" AS \"%s\"",


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