[tracker] libtracker-common, tracker-miner-fs: Make sure we load config files with



commit 5e7dedadeb87c099c3b4ad794c011b64ac9a2e74
Author: Martyn Russell <martyn lanedo com>
Date:   Wed Oct 2 11:49:44 2013 +0100

    libtracker-common, tracker-miner-fs: Make sure we load config files with
    
    When using TRACKER_USE_CONFIG_FILES env var.
    Before we would load the GKeyFile but not push that into the GObject config
    for each binary.

 src/libtracker-common/tracker-config-file.c |   87 +++++++++++++++++++++++++++
 src/libtracker-common/tracker-config-file.h |    5 ++
 src/libtracker-data/tracker-db-config.c     |    4 +-
 src/libtracker-fts/tracker-fts-config.c     |   12 ++--
 src/miners/fs/tracker-config.c              |   37 ++++++------
 src/tracker-store/tracker-config.c          |    2 +-
 src/tracker-writeback/tracker-config.c      |    2 +-
 7 files changed, 121 insertions(+), 28 deletions(-)
---
diff --git a/src/libtracker-common/tracker-config-file.c b/src/libtracker-common/tracker-config-file.c
index 6ad9898..604a836 100644
--- a/src/libtracker-common/tracker-config-file.c
+++ b/src/libtracker-common/tracker-config-file.c
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 
 #include "tracker-config-file.h"
+#include "tracker-keyfile-object.h"
 
 #ifdef CONFIG_ENABLE_TRACE
 #warning Config debugging traces enabled
@@ -306,6 +307,11 @@ config_load (TrackerConfigFile *file)
        g_free (basename);
        g_free (directory);
 
+#ifdef CONFIG_ENABLE_TRACE
+       g_message ("Loading config file:'%s'", filename);
+#endif /* CONFIG_ENABLE_TRACE */
+
+
        /* Add file monitoring for changes */
        if (!file->file) {
                file->file = g_file_new_for_path (filename);
@@ -423,6 +429,69 @@ tracker_config_file_new (void)
 }
 
 static gboolean
+load_keyfile_to_gobject (TrackerConfigMigrationEntry *entries,
+                         TrackerConfigFile           *file,
+                         GObject                     *object)
+{
+       gint i;
+
+       for (i = 0; entries[i].type != G_TYPE_INVALID; i++) {
+               if (!g_key_file_has_key (file->key_file,
+                                        entries[i].file_section,
+                                        entries[i].file_key,
+                                        NULL)) {
+                       /* Do nothing */
+                       continue;
+               }
+
+               switch (entries[i].type) {
+               case G_TYPE_INT:
+               case G_TYPE_ENUM:
+                       tracker_keyfile_object_load_int (object,
+                                                        entries[i].settings_key,
+                                                        file->key_file,
+                                                        entries[i].file_section,
+                                                        entries[i].file_key);
+                       break;
+
+               case G_TYPE_BOOLEAN:
+                       tracker_keyfile_object_load_boolean (object,
+                                                            entries[i].settings_key,
+                                                            file->key_file,
+                                                            entries[i].file_section,
+                                                            entries[i].file_key);
+                       break;
+
+               case G_TYPE_POINTER:
+                       if (entries[i].is_dir_list) {
+                               tracker_keyfile_object_load_directory_list (object,
+                                                                           entries[i].settings_key,
+                                                                           file->key_file,
+                                                                           entries[i].file_section,
+                                                                           entries[i].file_key,
+                                                                           entries[i].is_dir_list_recursive,
+                                                                           NULL);
+                       } else {
+                               tracker_keyfile_object_load_string_list (object,
+                                                                        entries[i].settings_key,
+                                                                        file->key_file,
+                                                                        entries[i].file_section,
+                                                                        entries[i].file_key,
+                                                                        NULL);
+                       }
+
+                       break;
+
+               default:
+                       g_assert_not_reached ();
+                       break;
+               }
+       }
+
+       return TRUE;
+}
+
+static gboolean
 migrate_keyfile_to_settings (TrackerConfigMigrationEntry *entries,
                              TrackerConfigFile           *file,
                              GSettings                   *settings)
@@ -643,3 +712,21 @@ tracker_config_file_import_to_settings (TrackerConfigFile           *file,
 
        return TRUE;
 }
+
+gboolean
+tracker_config_file_load_from_file (TrackerConfigFile           *file,
+                                    GObject                     *object,
+                                    TrackerConfigMigrationEntry *entries)
+{
+       g_return_val_if_fail (TRACKER_IS_CONFIG_FILE (file), FALSE);
+
+#ifdef CONFIG_ENABLE_TRACE
+       g_message ("Loading config file into GObject");
+#endif /* CONFIG_ENABLE_TRACE */
+
+       if (file->key_file && file->file_exists) {
+               load_keyfile_to_gobject (entries, file, object);
+       }
+
+       return TRUE;
+}
diff --git a/src/libtracker-common/tracker-config-file.h b/src/libtracker-common/tracker-config-file.h
index 9cc89df..ddc7a36 100644
--- a/src/libtracker-common/tracker-config-file.h
+++ b/src/libtracker-common/tracker-config-file.h
@@ -62,6 +62,8 @@ struct _TrackerConfigMigrationEntry {
        const gchar *file_section;
        const gchar *file_key;
        const gchar *settings_key;
+       gboolean is_dir_list;
+       gboolean is_dir_list_recursive;
 };
 
 GType              tracker_config_file_get_type           (void) G_GNUC_CONST;
@@ -72,6 +74,9 @@ gboolean           tracker_config_file_migrate            (TrackerConfigFile
 gboolean           tracker_config_file_import_to_settings (TrackerConfigFile           *file,
                                                            GSettings                   *settings,
                                                            TrackerConfigMigrationEntry *entries);
+gboolean           tracker_config_file_load_from_file     (TrackerConfigFile           *file,
+                                                           GObject                     *object,
+                                                           TrackerConfigMigrationEntry *entries);
 gboolean           tracker_config_file_save               (TrackerConfigFile           *file);
 
 G_END_DECLS
diff --git a/src/libtracker-data/tracker-db-config.c b/src/libtracker-data/tracker-db-config.c
index eb20b9a..3cd7423 100644
--- a/src/libtracker-data/tracker-db-config.c
+++ b/src/libtracker-data/tracker-db-config.c
@@ -56,8 +56,8 @@ enum {
 };
 
 static TrackerConfigMigrationEntry migration[] = {
-       { G_TYPE_INT, GROUP_JOURNAL, "JournalChunkSize", "journal-chunk-size" },
-       { G_TYPE_STRING, GROUP_JOURNAL, "JournalRotateDestination", "journal-rotate-destination" },
+       { G_TYPE_INT, GROUP_JOURNAL, "JournalChunkSize", "journal-chunk-size", FALSE, FALSE },
+       { G_TYPE_STRING, GROUP_JOURNAL, "JournalRotateDestination", "journal-rotate-destination", FALSE, 
FALSE },
 };
 
 G_DEFINE_TYPE (TrackerDBConfig, tracker_db_config, G_TYPE_SETTINGS);
diff --git a/src/libtracker-fts/tracker-fts-config.c b/src/libtracker-fts/tracker-fts-config.c
index 1fc9f32..19cc1ef 100644
--- a/src/libtracker-fts/tracker-fts-config.c
+++ b/src/libtracker-fts/tracker-fts-config.c
@@ -66,12 +66,12 @@ enum {
 };
 
 static TrackerConfigMigrationEntry migration[] = {
-       { G_TYPE_INT,     GROUP_INDEXING, "MaxWordLength",   "max-word-length"    },
-       { G_TYPE_BOOLEAN, GROUP_INDEXING, "EnableStemmer" ,  "enable-stemmer"     },
-       { G_TYPE_BOOLEAN, GROUP_INDEXING, "EnableUnaccent",  "enable-unaccent"    },
-       { G_TYPE_BOOLEAN, GROUP_INDEXING, "IgnoreNumbers",   "ignore-numbers"     },
-       { G_TYPE_BOOLEAN, GROUP_INDEXING, "IgnoreStopWords", "ignore-stop-words"  },
-       { G_TYPE_INT,     GROUP_INDEXING, "MaxWordsToIndex", "max-words-to-index" },
+       { G_TYPE_INT,     GROUP_INDEXING, "MaxWordLength",   "max-word-length",    FALSE, FALSE },
+       { G_TYPE_BOOLEAN, GROUP_INDEXING, "EnableStemmer" ,  "enable-stemmer",     FALSE, FALSE },
+       { G_TYPE_BOOLEAN, GROUP_INDEXING, "EnableUnaccent",  "enable-unaccent",    FALSE, FALSE },
+       { G_TYPE_BOOLEAN, GROUP_INDEXING, "IgnoreNumbers",   "ignore-numbers",     FALSE, FALSE },
+       { G_TYPE_BOOLEAN, GROUP_INDEXING, "IgnoreStopWords", "ignore-stop-words",  FALSE, FALSE },
+       { G_TYPE_INT,     GROUP_INDEXING, "MaxWordsToIndex", "max-words-to-index", FALSE, FALSE },
 };
 
 G_DEFINE_TYPE (TrackerFTSConfig, tracker_fts_config, G_TYPE_SETTINGS);
diff --git a/src/miners/fs/tracker-config.c b/src/miners/fs/tracker-config.c
index f288522..45972b5 100644
--- a/src/miners/fs/tracker-config.c
+++ b/src/miners/fs/tracker-config.c
@@ -129,24 +129,24 @@ enum {
 };
 
 static TrackerConfigMigrationEntry migration[] = {
-       { G_TYPE_ENUM,    "General",   "Verbosity",                     "verbosity"                        },
-       { G_TYPE_ENUM,    "General",   "SchedIdle",                     "sched-idle"                       },
-       { G_TYPE_INT,     "General",   "InitialSleep",                  "initial-sleep"                    },
-       { G_TYPE_BOOLEAN, "Monitors",  "EnableMonitors",                "enable-monitors"                  },
-       { G_TYPE_INT,     "Indexing",  "Throttle",                      "throttle"                         },
-       { G_TYPE_BOOLEAN, "Indexing",  "IndexOnBattery",                "index-on-battery"                 },
-       { G_TYPE_BOOLEAN, "Indexing",  "IndexOnBatteryFirstTime",       "index-on-battery-first-time"      },
-       { G_TYPE_BOOLEAN, "Indexing",  "IndexRemovableMedia",           "index-removable-devices"          },
-       { G_TYPE_BOOLEAN, "Indexing",  "IndexOpticalDiscs",             "index-optical-discs"              },
-       { G_TYPE_INT,     "Indexing",  "LowDiskSpaceLimit",             "low-disk-space-limit"             },
-       { G_TYPE_POINTER, "Indexing",  "IndexRecursiveDirectories",     "index-recursive-directories"      },
-       { G_TYPE_POINTER, "Indexing",  "IndexSingleDirectories",        "index-single-directories"         },
-       { G_TYPE_POINTER, "Indexing",  "IgnoredDirectories",            "ignored-directories"              },
-       { G_TYPE_POINTER, "Indexing",  "IgnoredDirectoriesWithContent", "ignored-directories-with-content" },
-       { G_TYPE_POINTER, "Indexing",  "IgnoredFiles",                  "ignored-files"                    },
-       { G_TYPE_INT,     "Indexing",  "CrawlingInterval",              "crawling-interval"                },
-       { G_TYPE_INT,     "Indexing",  "RemovableDaysThreshold",        "removable-days-threshold"         },
-       { G_TYPE_BOOLEAN, "Writeback", "EnableWriteback",               "enable-writeback"                 },
+       { G_TYPE_ENUM,    "General",   "Verbosity",                     "verbosity",                        
FALSE, FALSE },
+       { G_TYPE_ENUM,    "General",   "SchedIdle",                     "sched-idle",                       
FALSE, FALSE },
+       { G_TYPE_INT,     "General",   "InitialSleep",                  "initial-sleep",                    
FALSE, FALSE },
+       { G_TYPE_BOOLEAN, "Monitors",  "EnableMonitors",                "enable-monitors",                  
FALSE, FALSE },
+       { G_TYPE_INT,     "Indexing",  "Throttle",                      "throttle",                         
FALSE, FALSE },
+       { G_TYPE_BOOLEAN, "Indexing",  "IndexOnBattery",                "index-on-battery",                 
FALSE, FALSE },
+       { G_TYPE_BOOLEAN, "Indexing",  "IndexOnBatteryFirstTime",       "index-on-battery-first-time",      
FALSE, FALSE },
+       { G_TYPE_BOOLEAN, "Indexing",  "IndexRemovableMedia",           "index-removable-devices",          
FALSE, FALSE },
+       { G_TYPE_BOOLEAN, "Indexing",  "IndexOpticalDiscs",             "index-optical-discs",              
FALSE, FALSE },
+       { G_TYPE_INT,     "Indexing",  "LowDiskSpaceLimit",             "low-disk-space-limit",             
FALSE, FALSE },
+       { G_TYPE_POINTER, "Indexing",  "IndexRecursiveDirectories",     "index-recursive-directories",      
TRUE,  TRUE },
+       { G_TYPE_POINTER, "Indexing",  "IndexSingleDirectories",        "index-single-directories",         
TRUE,  FALSE },
+       { G_TYPE_POINTER, "Indexing",  "IgnoredDirectories",            "ignored-directories",              
FALSE, FALSE },
+       { G_TYPE_POINTER, "Indexing",  "IgnoredDirectoriesWithContent", "ignored-directories-with-content", 
FALSE, FALSE },
+       { G_TYPE_POINTER, "Indexing",  "IgnoredFiles",                  "ignored-files",                    
FALSE, FALSE },
+       { G_TYPE_INT,     "Indexing",  "CrawlingInterval",              "crawling-interval",                
FALSE, FALSE },
+       { G_TYPE_INT,     "Indexing",  "RemovableDaysThreshold",        "removable-days-threshold",         
FALSE, FALSE },
+       { G_TYPE_BOOLEAN, "Writeback", "EnableWriteback",               "enable-writeback",                 
FALSE, FALSE },
        { 0 }
 };
 
@@ -758,6 +758,7 @@ config_constructed (GObject *object)
                if (G_UNLIKELY (g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
                        TrackerConfigPrivate *priv;
 
+                       tracker_config_file_load_from_file (config_file, G_OBJECT (config), migration);
                        g_signal_connect (config_file, "changed", G_CALLBACK (config_file_changed_cb), 
config);
 
                        priv = config->priv;
diff --git a/src/tracker-store/tracker-config.c b/src/tracker-store/tracker-config.c
index ce03cf9..889c40c 100644
--- a/src/tracker-store/tracker-config.c
+++ b/src/tracker-store/tracker-config.c
@@ -48,7 +48,7 @@ enum {
 };
 
 static TrackerConfigMigrationEntry migration[] = {
-       { G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
+       { G_TYPE_ENUM, "General", "Verbosity", "verbosity", FALSE, FALSE },
        { 0 }
 };
 
diff --git a/src/tracker-writeback/tracker-config.c b/src/tracker-writeback/tracker-config.c
index b5ebd7d..659a027 100644
--- a/src/tracker-writeback/tracker-config.c
+++ b/src/tracker-writeback/tracker-config.c
@@ -50,7 +50,7 @@ enum {
 };
 
 static TrackerConfigMigrationEntry migration[] = {
-       { G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
+       { G_TYPE_ENUM, "General", "Verbosity", "verbosity", FALSE, FALSE },
        { 0 }
 };
 


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