[tracker/domain-ontologies] libtracker-data, tracker-store: domain specific ontologies



commit 47893dc50f62d3cef5dfe63e472a7ffc149dad1e
Author: Philip Van Hoof <philip codeminded be>
Date:   Sat Jan 28 01:06:06 2017 +0100

    libtracker-data, tracker-store: domain specific ontologies

 src/libtracker-data/tracker-data-backup.c  |    6 +-
 src/libtracker-data/tracker-data-backup.h  |    2 +-
 src/libtracker-data/tracker-data-manager.c |    3 +
 src/libtracker-data/tracker-db-manager.c   |   97 +++++++++++++++++-----------
 src/libtracker-data/tracker-db-manager.h   |    2 +-
 src/tracker-store/tracker-main.vala        |   13 +++-
 6 files changed, 76 insertions(+), 47 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index 79d6334..fef3582 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -556,7 +556,7 @@ tracker_data_backup_save (GFile                     *destination,
 void
 tracker_data_backup_restore (GFile                *journal,
                              const gchar          *domain,
-                             const gchar          *ontology,
+                             const gchar          *ontology_name,
                              const gchar         **test_schemas,
                              TrackerBusyCallback   busy_callback,
                              gpointer              busy_user_data,
@@ -655,7 +655,7 @@ tracker_data_backup_restore (GFile                *journal,
                             &info->error);
 #endif /* DISABLE_JOURNAL */
 
-               tracker_db_manager_init_locations ();
+               tracker_db_manager_init_locations (domain, ontology_name);
 
                /* Re-set the DB version file, so that its mtime changes. The mtime of this
                 * file will change only when the whole DB is recreated (after a hard reset
@@ -696,7 +696,7 @@ tracker_data_backup_restore (GFile                *journal,
                }
 #endif /* DISABLE_JOURNAL */
 
-               tracker_data_manager_init (flags, domain, ontology, test_schemas,
+               tracker_data_manager_init (flags, domain, ontology_name, test_schemas,
                                           &is_first, TRUE, TRUE,
                                           select_cache_size, update_cache_size,
                                           busy_callback, busy_user_data,
diff --git a/src/libtracker-data/tracker-data-backup.h b/src/libtracker-data/tracker-data-backup.h
index fb15427..3d05573 100644
--- a/src/libtracker-data/tracker-data-backup.h
+++ b/src/libtracker-data/tracker-data-backup.h
@@ -49,7 +49,7 @@ void   tracker_data_backup_save        (GFile                     *destination,
                                         GDestroyNotify             destroy);
 void   tracker_data_backup_restore     (GFile                     *journal,
                                         const gchar               *domain,
-                                        const gchar               *ontology,
+                                        const gchar               *ontology_name,
                                         const gchar              **test_schema,
                                         TrackerBusyCallback        busy_callback,
                                         gpointer                   busy_user_data,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index b7741db..c533fce 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3828,6 +3828,9 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                           ontology_name,
                                                           NULL);
                }
+               if (!g_file_test (ontologies_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
+                       g_critical ("%s is not a directory with an ontology", ontologies_dir);
+               }
        } else {
                ontologies_dir = g_strdup (env_path);
        }
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index ed4c8ad..fffbfc6 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -658,7 +658,7 @@ tracker_db_manager_locale_changed (GError **error)
         * to check for locale mismatches for initializing the database.
         */
        if (!locations_initialized) {
-               tracker_db_manager_init_locations ();
+               tracker_db_manager_init_locations (in_use_domain, in_use_ontology_name);
        }
 
        /* Get current collation locale */
@@ -787,7 +787,7 @@ db_recreate_all (GError **error)
 }
 
 void
-tracker_db_manager_init_locations (void)
+tracker_db_manager_init_locations (const char *domain, const char *ontology_name)
 {
        const gchar *dir;
        guint i;
@@ -796,17 +796,26 @@ tracker_db_manager_init_locations (void)
                return;
        }
 
+       if (domain == NULL) {
+               domain = "tracker";
+       }
        user_data_dir = g_build_filename (g_get_user_data_dir (),
-                                         "tracker",
+                                         domain,
                                          "data",
                                          NULL);
 
        /* For DISABLE_JOURNAL case we should use g_get_user_data_dir here. For now
         * keeping this as-is */
 
-       data_dir = g_build_filename (g_get_user_cache_dir (),
-                                    "tracker",
-                                    NULL);
+       if (ontology_name == NULL) {
+               data_dir = g_build_filename (g_get_user_cache_dir (),
+                                            domain,
+                                            NULL);
+       } else {
+               data_dir = g_build_filename (g_get_user_cache_dir (),
+                                            domain, ontology_name,
+                                            NULL);
+       }
 
        for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
                dir = location_to_directory (dbs[i].location);
@@ -900,33 +909,35 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
 
        old_flags = flags;
 
-       tracker_db_manager_init_locations ();
-
        g_free (in_use_filename);
-    g_free (in_use_domain);
-    g_free (in_use_ontology_name);
-
-    if (domain == NULL) {
-        domain = "tracker";
-
-    }
-    in_use_domain = g_strdup (domain);
-
-    if (ontology_name == NULL) {
-        in_use_ontology_name = NULL;
-        in_use_filename = g_build_filename (g_get_user_data_dir (),
-                                            domain,
-                                            "data",
-                                            IN_USE_FILENAME,
-                                            NULL);
-    } else {
-        in_use_ontology_name = g_strdup (ontology_name);
-        in_use_filename = g_build_filename (g_get_user_data_dir (),
-                                            domain, ontology_name,
-                                            "data",
-                                            IN_USE_FILENAME,
-                                            NULL);
-    }
+       g_free (in_use_domain);
+       g_free (in_use_ontology_name);
+
+       if (domain == NULL)
+               domain = "tracker";
+       in_use_domain = g_strdup (domain);
+
+       if (ontology_name == NULL)
+               in_use_ontology_name = NULL;
+       else
+               in_use_ontology_name = g_strdup (ontology_name);
+
+       in_use_domain = g_strdup (domain);
+
+       tracker_db_manager_init_locations (domain, ontology_name);
+       if (ontology_name == NULL) {
+               in_use_filename = g_build_filename (g_get_user_data_dir (),
+                                                   domain,
+                                                   "data",
+                                                   IN_USE_FILENAME,
+                                                   NULL);
+       } else {
+               in_use_filename = g_build_filename (g_get_user_data_dir (),
+                                                   domain, ontology_name,
+                                                   "data",
+                                                   IN_USE_FILENAME,
+                                                   NULL);
+       }
 
        /* Don't do need_reindex checks for readonly (direct-access) */
        if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
@@ -1045,19 +1056,27 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                /* do not do shutdown check for read-only mode (direct access) */
                gboolean must_recreate = FALSE;
 #ifndef DISABLE_JOURNAL
-               gchar *journal_filename;
+               gchar *journal_filename, *jfname;
 #endif /* DISABLE_JOURNAL */
 
                /* Load databases */
                g_message ("Loading databases files...");
 
 #ifndef DISABLE_JOURNAL
-               journal_filename = g_build_filename (g_get_user_data_dir (),
-                                                    "tracker",
-                                                    "data",
-                                                    TRACKER_DB_JOURNAL_FILENAME,
-                                                    NULL);
-
+               if (ontology_name == NULL) {
+                       journal_filename = g_build_filename (g_get_user_data_dir (),
+                                                            domain,
+                                                            "data",
+                                                            TRACKER_DB_JOURNAL_FILENAME,
+                                                            NULL);
+               } else {
+                       journal_filename = g_build_filename (g_get_user_data_dir (),
+                                                            domain,
+                                                            ontology_name,
+                                                            "data",
+                                                            TRACKER_DB_JOURNAL_FILENAME,
+                                                            NULL);
+               }
                must_recreate = !tracker_db_journal_reader_verify_last (journal_filename,
                                                                        NULL);
 
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index a763b45..cfe7408 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -69,7 +69,7 @@ void                tracker_db_manager_remove_all             (gboolean
 void                tracker_db_manager_optimize               (void);
 const gchar *       tracker_db_manager_get_file               (TrackerDB              db);
 TrackerDBInterface *tracker_db_manager_get_db_interface       (void);
-void                tracker_db_manager_init_locations         (void);
+void                tracker_db_manager_init_locations         (const gchar *domain, const gchar 
*ontology_name);
 gboolean            tracker_db_manager_has_enough_space       (void);
 void                tracker_db_manager_create_version_file    (void);
 void                tracker_db_manager_remove_version_file    (void);
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index 380b6ac..06ab62d 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -41,7 +41,9 @@ License which can be viewed at:
        static int verbosity;
        static bool force_reindex;
        static bool readonly_mode;
-
+       static string domain;
+       static string ontology_name;
+       
        const OptionEntry entries[] = {
                /* Daemon options */
                { "version", 'V', 0, OptionArg.NONE, ref version, N_("Displays version information"), null },
@@ -50,6 +52,9 @@ License which can be viewed at:
                /* Indexer options */
                { "force-reindex", 'r', 0, OptionArg.NONE, ref force_reindex, N_("Force a re-index of all 
content"), null },
                { "readonly-mode", 'n', 0, OptionArg.NONE, ref readonly_mode, N_("Only allow read based 
actions on the database"), null },
+               { "domain", 'd', 0, OptionArg.STRING, ref domain, N_("Domain to be used"), null },
+               { "ontology-name", 'o', 0, OptionArg.STRING, ref ontology_name, N_("Ontology to be used"), 
null },
+
                { null }
        };
 
@@ -60,6 +65,9 @@ License which can be viewed at:
                message ("Store options:");
                message ("  Readonly mode  ........................  %s", readonly_mode ? "yes" : "no");
                message ("  GraphUpdated Delay ....................  %d", config.graphupdated_delay);
+               message ("  Domain         ........................  %s", domain);
+               message ("  Ontology name  ........................  %s", ontology_name);
+
        }
 
        static void do_shutdown () {
@@ -260,8 +268,7 @@ License which can be viewed at:
                bool is_first_time_index;
 
                try {
-                       // TODO: Set domain and ontology name here
-                       Tracker.Data.Manager.init (flags, null, null,
+                       Tracker.Data.Manager.init (flags, domain, ontology_name,
                                                   null,
                                                   out is_first_time_index,
                                                   true,


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