[tracker/wip/carlosg/sparql1.1: 144/145] libtracker-data: Store tokenizer version inside meta.db



commit 1a7ee4261a749331b9cfc2378ddde786a724192c
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jul 18 22:33:50 2019 +0200

    libtracker-data: Store tokenizer version inside meta.db
    
    Use the metadata table for this, instead of a separate file.

 src/libtracker-data/tracker-data-manager.c |  1 +
 src/libtracker-data/tracker-db-manager.c   | 45 +++++++++---------------------
 2 files changed, 14 insertions(+), 32 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index f165eb241..fe9868702 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -4959,6 +4959,7 @@ tracker_data_manager_initable_init (GInitable     *initable,
 skip_ontology_check:
        if (!read_only && is_first_time_index) {
                tracker_db_manager_set_current_locale (manager->db_manager);
+               tracker_db_manager_tokenizer_update (manager->db_manager);
        } else if (!read_only && tracker_db_manager_locale_changed (manager->db_manager, NULL)) {
                /* If locale changed, re-create indexes.
                 * No need to reset the collator in the db interface,
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 0a1a75439..207eb13d9 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -66,8 +66,6 @@
 
 #define IN_USE_FILENAME               ".meta.isrunning"
 
-#define PARSER_VERSION_FILENAME       "parser-version.txt"
-
 #define TOSTRING1(x) #x
 #define TOSTRING(x) TOSTRING1(x)
 #define TRACKER_PARSER_VERSION_STRING TOSTRING(TRACKER_PARSER_VERSION)
@@ -1224,29 +1222,19 @@ tracker_db_manager_has_enough_space (TrackerDBManager *db_manager)
        return tracker_file_system_has_enough_space (db_manager->data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, 
FALSE);
 }
 
-inline static gchar *
-get_parser_version_filename (TrackerDBManager *db_manager)
-{
-       return g_build_filename (db_manager->data_dir,
-                                PARSER_VERSION_FILENAME,
-                                NULL);
-}
-
-
 gboolean
 tracker_db_manager_get_tokenizer_changed (TrackerDBManager *db_manager)
 {
-       gchar *filename, *version;
-       gboolean changed = TRUE;
+       GValue value = G_VALUE_INIT;
+       const gchar *version;
+       gboolean changed;
 
-       filename = get_parser_version_filename (db_manager);
+       if (!tracker_db_manager_get_metadata (db_manager, "parser-version", &value))
+               return TRUE;
 
-       if (g_file_get_contents (filename, &version, NULL, NULL)) {
-               changed = strcmp (version, TRACKER_PARSER_VERSION_STRING) != 0;
-               g_free (version);
-       }
-
-       g_free (filename);
+       version = g_value_get_string (&value);
+       changed = strcmp (version, TRACKER_PARSER_VERSION_STRING) != 0;
+       g_value_unset (&value);
 
        return changed;
 }
@@ -1254,20 +1242,13 @@ tracker_db_manager_get_tokenizer_changed (TrackerDBManager *db_manager)
 void
 tracker_db_manager_tokenizer_update (TrackerDBManager *db_manager)
 {
-       GError *error = NULL;
-       gchar *filename;
-
-       filename = get_parser_version_filename (db_manager);
+       GValue value = G_VALUE_INIT;
 
-       if (!g_file_set_contents (filename, TRACKER_PARSER_VERSION_STRING, -1, &error)) {
-               g_warning ("The file '%s' could not be rewritten by Tracker and "
-                          "should be deleted manually. Not doing so will result "
-                          "in Tracker rebuilding its FTS tokens on every startup. "
-                          "The error received was: '%s'", filename, error->message);
-               g_error_free (error);
-       }
+       g_value_init (&value, G_TYPE_STRING);
+       g_value_set_string (&value, TRACKER_PARSER_VERSION_STRING);
 
-       g_free (filename);
+       tracker_db_manager_set_metadata (db_manager, "parser-version", &value);
+       g_value_unset (&value);
 }
 
 void


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