[tracker/wip/carlosg/domain-ontologies: 12/93] Domain-ontologies: allow more flexibility on locations. Example:



commit 211935fa2cca42634f88957b16e5c6425319fe22
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Jan 30 23:55:26 2017 +0100

    Domain-ontologies: allow more flexibility on locations. Example:
    
    /opt/tracker/share# cat tracker/domain-ontologies/test.rule
    
    [DomainOntology]
    DataLocation=%HOME%/.cache/test/data
    CacheLocation=%HOME%/.cache/test/cache
    OntologyLocation=%SHAREDIR%/tracker/ontologies
    Domain=test
    DBusPath=/test
    OntologyName=test

 src/libtracker-data/libtracker-data.vapi   |    4 +-
 src/libtracker-data/tracker-data-backup.c  |  106 +++++++++++++++--------
 src/libtracker-data/tracker-data-backup.h  |    6 +-
 src/libtracker-data/tracker-data-manager.c |  113 ++++++++++++++++---------
 src/libtracker-data/tracker-data-manager.h |   12 ++-
 src/libtracker-data/tracker-data-update.c  |    5 +-
 src/libtracker-data/tracker-db-journal.c   |   19 +++--
 src/libtracker-data/tracker-db-journal.h   |    2 +
 src/libtracker-data/tracker-db-manager.c   |  126 +++++++++++++++-------------
 src/libtracker-data/tracker-db-manager.h   |   10 +--
 src/tracker-store/tracker-backup.vala      |    2 +-
 src/tracker-store/tracker-main.vala        |   63 ++++++++++----
 src/tracker/tracker-reset.c                |    4 +-
 tests/libtracker-data/tracker-db-journal.c |    6 +-
 14 files changed, 297 insertions(+), 181 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 930e1af..dd641e5 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -224,12 +224,12 @@ namespace Tracker {
                public delegate void BackupFinished (GLib.Error error);
 
                public void backup_save (GLib.File destination, owned BackupFinished callback);
-               public void backup_restore (GLib.File journal, string? loc, string? domain, string? 
ontology_name, [CCode (array_length = false)] string[]? test_schema, BusyCallback busy_callback) throws 
GLib.Error;
+               public void backup_restore (GLib.File journal, string? cache_location, string? data_location, 
string? ontology_location, [CCode (array_length = false)] string[]? test_schema, BusyCallback busy_callback) 
throws GLib.Error;
        }
 
        [CCode (cheader_filename = "libtracker-data/tracker-data-manager.h")]
        namespace Data.Manager {
-               public bool init (DBManagerFlags flags, string? loc, string? domain, string? ontology_name, 
[CCode (array_length = false)] string[]? test_schema, out bool first_time, bool journal_check, bool 
restoring_backup, uint select_cache_size, uint update_cache_size, BusyCallback? busy_callback, string? 
busy_status) throws DBInterfaceError, DBJournalError;
+               public bool init (DBManagerFlags flags, string? cache_location, string? data_location, 
string? ontology_location, [CCode (array_length = false)] string[]? test_schema, out bool first_time, bool 
journal_check, bool restoring_backup, uint select_cache_size, uint update_cache_size, BusyCallback? 
busy_callback, string? busy_status) throws DBInterfaceError, DBJournalError;
                public void shutdown ();
        }
 
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index dc4a5b5..5065f1f 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -343,20 +343,28 @@ dir_move_from_temp (const gchar *path)
 }
 
 static void
-move_to_temp (void)
+move_to_temp (const gchar* cache_location, const gchar* data_location)
 {
        gchar *data_dir, *cache_dir;
 
        g_message ("Moving all database files to temporary location");
 
-       data_dir = g_build_filename (g_get_user_data_dir (),
-                                    "tracker",
-                                    "data",
-                                    NULL);
-
-       cache_dir = g_build_filename (g_get_user_cache_dir (),
-                                     "tracker",
-                                     NULL);
+       if (data_location == NULL) {
+               data_dir = g_build_filename (g_get_user_data_dir (),
+                                            "tracker",
+                                            "data",
+                                            NULL);
+       } else {
+               data_dir = g_strdup (data_location);
+       }
+       
+       if (cache_location == NULL) {
+               cache_dir = g_build_filename (g_get_user_cache_dir (),
+                                             "tracker",
+                                             NULL);
+       } else {
+               cache_dir = g_strdup(cache_location);
+       }
 
        dir_move_to_temp (data_dir);
        dir_move_to_temp (cache_dir);
@@ -366,22 +374,34 @@ move_to_temp (void)
 }
 
 static void
-remove_temp (void)
+remove_temp (const gchar* cache_location, const gchar* data_location)
 {
        gchar *tmp_data_dir, *tmp_cache_dir;
 
        g_message ("Removing all database files from temporary location");
 
-       tmp_data_dir = g_build_filename (g_get_user_data_dir (),
-                                        "tracker",
-                                        "data",
-                                        "tmp",
-                                        NULL);
+       if (data_location == NULL) {
+               tmp_data_dir = g_build_filename (g_get_user_data_dir (),
+                                                "tracker",
+                                                "data",
+                                                "tmp",
+                                                NULL);
+       } else {
+               tmp_data_dir = g_build_filename (data_location,
+                                                "tmp",
+                                                NULL);
+       }
 
-       tmp_cache_dir = g_build_filename (g_get_user_cache_dir (),
-                                         "tracker",
-                                         "tmp",
-                                         NULL);
+       if (cache_location == NULL) {
+               tmp_cache_dir = g_build_filename (g_get_user_cache_dir (),
+                                                 "tracker",
+                                                 "tmp",
+                                                 NULL);
+       } else {
+               tmp_cache_dir = g_build_filename (cache_location,
+                                                 "tmp",
+                                                 NULL);
+       }
 
        dir_remove_files (tmp_data_dir);
        dir_remove_files (tmp_cache_dir);
@@ -394,20 +414,28 @@ remove_temp (void)
 }
 
 static void
-restore_from_temp (void)
+restore_from_temp (const gchar* cache_location, const gchar* data_location)
 {
        gchar *data_dir, *cache_dir;
 
        g_message ("Restoring all database files from temporary location");
 
-       data_dir = g_build_filename (g_get_user_data_dir (),
-                                    "tracker",
-                                    "data",
-                                    NULL);
+       if (data_location == NULL) {
+               data_dir = g_build_filename (g_get_user_data_dir (),
+                                            "tracker",
+                                            "data",
+                                            NULL);
+       } else {
+               data_dir = g_strdup (data_location);
+       }
 
-       cache_dir = g_build_filename (g_get_user_cache_dir (),
-                                     "tracker",
-                                     NULL);
+       if (cache_location == NULL) {
+               cache_dir = g_build_filename (g_get_user_cache_dir (),
+                                             "tracker",
+                                             NULL);
+       } else {
+               cache_dir = g_strdup (cache_location);
+       }
 
        dir_move_from_temp (data_dir);
        dir_move_from_temp (cache_dir);
@@ -555,9 +583,9 @@ tracker_data_backup_save (GFile                     *destination,
 
 void
 tracker_data_backup_restore (GFile                *journal,
-                             const gchar          *loc,
-                             const gchar          *domain,
-                             const gchar          *ontology_name,
+                             const gchar          *cache_location,
+                             const gchar          *data_location,
+                             const gchar          *ontology_location,
                              const gchar         **test_schemas,
                              TrackerBusyCallback   busy_callback,
                              gpointer              busy_user_data,
@@ -593,7 +621,7 @@ tracker_data_backup_restore (GFile                *journal,
 
                tracker_data_manager_shutdown ();
 
-               move_to_temp ();
+               move_to_temp (cache_location, data_location);
 
 #ifndef DISABLE_JOURNAL
                argv = g_new0 (char*, 6);
@@ -656,7 +684,7 @@ tracker_data_backup_restore (GFile                *journal,
                             &info->error);
 #endif /* DISABLE_JOURNAL */
 
-               tracker_db_manager_init_locations (loc, domain, ontology_name);
+               tracker_db_manager_init_locations (cache_location, data_location);
 
                /* 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
@@ -669,7 +697,7 @@ tracker_data_backup_restore (GFile                *journal,
                tracker_db_manager_set_need_mtime_check (TRUE);
 
 #ifndef DISABLE_JOURNAL
-               tracker_db_journal_init (NULL, FALSE, &n_error);
+               tracker_db_journal_init (NULL, cache_location, data_location, FALSE, &n_error);
 
                if (n_error) {
                        if (!info->error) {
@@ -683,9 +711,9 @@ tracker_data_backup_restore (GFile                *journal,
                }
 
                if (info->error) {
-                       restore_from_temp ();
+                       restore_from_temp (cache_location, data_location);
                } else {
-                       remove_temp ();
+                       remove_temp (cache_location, data_location);
                }
 
                tracker_db_journal_shutdown (&n_error);
@@ -697,7 +725,7 @@ tracker_data_backup_restore (GFile                *journal,
                }
 #endif /* DISABLE_JOURNAL */
 
-               tracker_data_manager_init (flags, loc, domain, ontology_name, test_schemas,
+               tracker_data_manager_init (flags, cache_location, data_location, ontology_location, 
test_schemas,
                                           &is_first, TRUE, TRUE,
                                           select_cache_size, update_cache_size,
                                           busy_callback, busy_user_data,
@@ -707,7 +735,11 @@ tracker_data_backup_restore (GFile                *journal,
                if (internal_error) {
                        restore_from_temp ();
 
-                       tracker_data_manager_init (flags, test_schemas, &is_first, TRUE, TRUE,
+                       tracker_data_manager_init (flags,
+                                                  cache_location,
+                                                  data_location,
+                                                  ontology_location,
+                                                  test_schemas, &is_first, TRUE, TRUE,
                                                   select_cache_size, update_cache_size,
                                                   busy_callback, busy_user_data,
                                                   "Restoring backup", &internal_error);
diff --git a/src/libtracker-data/tracker-data-backup.h b/src/libtracker-data/tracker-data-backup.h
index e3060e6..e02bbc0 100644
--- a/src/libtracker-data/tracker-data-backup.h
+++ b/src/libtracker-data/tracker-data-backup.h
@@ -48,9 +48,9 @@ void   tracker_data_backup_save        (GFile                     *destination,
                                         gpointer                   user_data,
                                         GDestroyNotify             destroy);
 void   tracker_data_backup_restore     (GFile                     *journal,
-                                        const gchar               *loc,
-                                        const gchar               *domain,
-                                        const gchar               *ontology_name,
+                                        const gchar               *cache_location,
+                                        const gchar               *data_location,
+                                        const gchar               *ontology_location,
                                         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 0de3cb4..a8260a1 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -66,9 +66,9 @@
 #define ZLIBBUFSIZ 8192
 
 static gchar    *ontologies_dir;
-static gchar    *ontology_name_stored;
-static gchar    *loc_stored;
-static gchar    *domain_stored;
+static gchar    *ontology_location_stored;
+static gchar    *cache_location_stored;
+static gchar    *data_location_stored;
 static gboolean  initialized;
 static gboolean  reloading = FALSE;
 #ifndef DISABLE_JOURNAL
@@ -3534,7 +3534,9 @@ tracker_data_manager_reload (TrackerBusyCallback   busy_callback,
 
        /* And initialize it again, this actually triggers index recreation. */
        status = tracker_data_manager_init (flags,
-                                           loc_stored, domain_stored,  ontology_name_stored,
+                                           cache_location_stored,
+                                           data_location_stored,
+                                           ontology_location_stored,
                                            NULL,
                                            &is_first,
                                            TRUE,
@@ -3673,11 +3675,21 @@ tracker_data_manager_init_fts (TrackerDBInterface *iface,
 #endif
 }
 
+const gchar * tracker_data_manager_get_cache_location()
+{
+       return cache_location_stored;
+}
+
+const gchar * tracker_data_manager_get_data_location ()
+{
+       return data_location_stored;
+}
+
 gboolean
 tracker_data_manager_init (TrackerDBManagerFlags   flags,
-                           const gchar            *loc,
-                           const gchar            *domain,
-                           const gchar            *ontology_name,
+                           const gchar            *cache_location,
+                           const gchar            *data_location,
+                           const gchar            *ontology_location,
                            const gchar           **test_schemas,
                            gboolean               *first_time,
                            gboolean                journal_check,
@@ -3736,7 +3748,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 #endif
 
        if (!tracker_db_manager_init (flags,
-                                     loc, domain, ontology_name,
+                                     cache_location,
+                                     data_location,
                                      &is_first_time_index,
                                      restoring_backup,
                                      FALSE,
@@ -3806,40 +3819,47 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
        env_path = g_getenv ("TRACKER_DB_ONTOLOGIES_DIR");
 
-       g_free (loc_stored);
-
-       if (loc != NULL)
-               loc_stored = g_strdup(loc);
+       g_free (cache_location_stored);
+       if (cache_location != NULL)
+               cache_location_stored = g_strdup(cache_location);
        else
-               loc_stored = NULL;
+               cache_location_stored = NULL;
 
-       g_free (ontology_name_stored);
+       g_free (ontology_location_stored);
+       if (ontology_location != NULL)
+               ontology_location_stored = g_strdup(ontology_location);
+       else
+               ontology_location_stored = NULL;
 
-       if (ontology_name != NULL)
-               ontology_name_stored = g_strdup(ontology_name);
+       g_free (data_location_stored);
+       if (data_location != NULL)
+               data_location_stored = g_strdup(data_location);
        else
-               ontology_name = NULL;
+               data_location_stored = NULL;
 
-       if (domain == NULL)
-               domain = "tracker";
-       g_free (domain_stored);
-       domain_stored = g_strdup(domain);
 
        if (G_LIKELY (!env_path)) {
-               if (ontology_name == NULL) {
-                       ontologies_dir = g_build_filename (SHAREDIR,
-                                                          domain,
-                                                          "ontologies",
-                                                          NULL);
+               if (ontology_location == NULL) {
+                       /* SHAREDIR/tracker/ontologies */
+                       ontologies_dir = g_build_filename (SHAREDIR, "tracker",
+                                                          "ontologies", NULL);
                } else {
-                       ontologies_dir = g_build_filename (SHAREDIR,
-                                                          domain,
-                                                          "ontologies",
-                                                          ontology_name,
-                                                          NULL);
+                       /* Typically SHAREDIR/tracker/domain-ontologies/domain/ontology-name */
+                       ontologies_dir = g_strdup (ontology_location);
                }
+
+               /* TODO: support GResource here */
                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);
+                       g_set_error (error, TRACKER_DATA_ONTOLOGY_ERROR,
+                                    TRACKER_DATA_ONTOLOGY_NOT_FOUND,
+                                    "'%s' is not a ontology location", ontologies_dir);
+                       tracker_db_manager_shutdown ();
+                       tracker_ontologies_shutdown ();
+                       if (!reloading) {
+                               tracker_locale_shutdown ();
+                       }
+                       tracker_data_update_shutdown ();
+                       return FALSE;
                }
        } else {
                ontologies_dir = g_strdup (env_path);
@@ -3857,8 +3877,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                } else {
                        if (internal_error) {
                                if (!g_error_matches (internal_error,
-                                                     TRACKER_DB_JOURNAL_ERROR,
-                                                     TRACKER_DB_JOURNAL_ERROR_BEGIN_OF_JOURNAL)) {
+                                                         TRACKER_DB_JOURNAL_ERROR,
+                                                         TRACKER_DB_JOURNAL_ERROR_BEGIN_OF_JOURNAL)) {
                                        g_propagate_error (error, internal_error);
 
                                        tracker_db_manager_shutdown ();
@@ -3890,7 +3910,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                if (!read_journal) {
                        /* Truncate journal as it does not even contain a single valid transaction
                         * or is explicitly ignored (journal_check == FALSE, only for test cases) */
-                       tracker_db_journal_init (NULL, TRUE, &internal_error);
+                       tracker_db_journal_init (NULL, cache_location, data_location,
+                                                TRUE, &internal_error);
 
                        if (internal_error) {
                                g_propagate_error (error, internal_error);
@@ -3913,6 +3934,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        GError *ontology_error = NULL;
                        gchar *ontology_path;
                        g_debug ("Loading ontology %s", (char *) l->data);
+                       
+                       /* TODO: support GResource here */
                        ontology_path = g_build_filename (ontologies_dir, l->data, NULL);
                        load_ontology_file_from_path (ontology_path,
                                                      &max_id,
@@ -4024,6 +4047,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
                /* store ontology in database */
                for (l = sorted; l; l = l->next) {
+                       /* TODO: support GResource here */
                        gchar *ontology_path = g_build_filename (ontologies_dir, l->data, NULL);
                        import_ontology_path (ontology_path, FALSE, !journal_check);
                        g_free (ontology_path);
@@ -4069,7 +4093,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                if (!read_only) {
 
 #ifndef DISABLE_JOURNAL
-                       tracker_db_journal_init (NULL, FALSE, &internal_error);
+                       tracker_db_journal_init (NULL, cache_location, data_location,
+                                                FALSE, &internal_error);
 
                        if (internal_error) {
                                g_propagate_error (error, internal_error);
@@ -4139,6 +4164,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
                for (l = sorted; l; l = l->next) {
                        gchar *ontology_path;
+                       /* TODO: support GResource here */
                        ontology_path = g_build_filename (ontologies_dir, l->data, NULL);
                        ontos = g_list_append (ontos, ontology_path);
                }
@@ -4298,7 +4324,9 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                tracker_data_manager_shutdown ();
 
                                                return tracker_data_manager_init (flags | 
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
-                                                                                 loc, domain, ontology_name,
+                                                                                 cache_location,
+                                                                                 data_location,
+                                                                                 ontology_location,
                                                                                  test_schemas,
                                                                                  first_time,
                                                                                  journal_check,
@@ -4389,7 +4417,9 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                        tracker_data_manager_shutdown ();
 
                                        return tracker_data_manager_init (flags | 
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
-                                                                         loc, domain, ontology_name,
+                                                                         cache_location,
+                                                                         data_location,
+                                                                         ontology_location,
                                                                          test_schemas,
                                                                          first_time,
                                                                          journal_check,
@@ -4497,7 +4527,9 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                tracker_data_manager_shutdown ();
 
                                return tracker_data_manager_init (flags | 
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
-                                                                 loc, domain, ontology_name,
+                                                                 cache_location,
+                                                                 data_location,
+                                                                 ontology_location,
                                                                  test_schemas,
                                                                  first_time,
                                                                  journal_check,
@@ -4616,7 +4648,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                in_journal_replay = FALSE;
 
                /* open journal for writing */
-               tracker_db_journal_init (NULL, FALSE, &internal_error);
+               tracker_db_journal_init (NULL, cache_location, data_location,
+                                        FALSE, &internal_error);
 
                if (internal_error) {
                        g_hash_table_unref (uri_id_map);
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 5d0958c..0dcd210 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -41,14 +41,15 @@ G_BEGIN_DECLS
 #define TRACKER_DATA_ONTOLOGY_ERROR                  (tracker_data_ontology_error_quark ())
 
 typedef enum {
-       TRACKER_DATA_UNSUPPORTED_ONTOLOGY_CHANGE
+       TRACKER_DATA_UNSUPPORTED_ONTOLOGY_CHANGE,
+       TRACKER_DATA_ONTOLOGY_NOT_FOUND,
 } TrackerDataOntologyError;
 
 GQuark   tracker_data_ontology_error_quark           (void);
 gboolean tracker_data_manager_init                   (TrackerDBManagerFlags   flags,
-                                                      const gchar            *loc,
-                                                      const gchar            *domain,
-                                                      const gchar            *ontology_name,
+                                                      const gchar            *ontology_location,
+                                                      const gchar            *cache_location,
+                                                      const gchar            *data_location,
                                                       const gchar           **test_schema,
                                                       gboolean               *first_time,
                                                       gboolean                journal_check,
@@ -66,6 +67,9 @@ gboolean tracker_data_manager_reload                 (TrackerBusyCallback     bu
                                                       const gchar            *busy_operation,
                                                       GError                **error);
 
+const gchar * tracker_data_manager_get_cache_location();
+const gchar * tracker_data_manager_get_data_location ();
+
 gboolean tracker_data_manager_init_fts               (TrackerDBInterface     *interface,
                                                      gboolean                create);
 
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 9928bce..a62ff7a 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -3837,7 +3837,10 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
                size = tracker_db_journal_reader_get_size_of_correct ();
                tracker_db_journal_reader_shutdown ();
 
-               tracker_db_journal_init (NULL, FALSE, &n_error);
+               const gchar *cache_location = tracker_data_manager_get_cache_location();
+               const gchar *data_location = tracker_data_manager_get_data_location();
+
+               tracker_db_journal_init (NULL, cache_location, data_location, FALSE, &n_error);
                if (n_error) {
                        g_clear_error (&journal_error);
                        /* This is fatal (journal file not writable, etc) */
diff --git a/src/libtracker-data/tracker-db-journal.c b/src/libtracker-data/tracker-db-journal.c
index d82f7ca..d7e4fc3 100644
--- a/src/libtracker-data/tracker-db-journal.c
+++ b/src/libtracker-data/tracker-db-journal.c
@@ -564,6 +564,8 @@ db_journal_writer_init (JournalWriter  *jwriter,
 
 gboolean
 tracker_db_journal_init (const gchar  *filename,
+                         const gchar  *cache_location,
+                         const gchar  *data_location,
                          gboolean      truncate,
                          GError      **error)
 {
@@ -575,12 +577,17 @@ tracker_db_journal_init (const gchar  *filename,
        g_return_val_if_fail (writer.journal == 0, FALSE);
 
        if (filename == NULL) {
-               /* Used mostly for testing */
-               filename_use = g_build_filename (g_get_user_data_dir (),
-                                                "tracker",
-                                                "data",
-                                                TRACKER_DB_JOURNAL_FILENAME,
-                                                NULL);
+               if (data_location == NULL) {
+                       filename_use = g_build_filename (g_get_user_data_dir (),
+                                                        "tracker",
+                                                        "data",
+                                                        TRACKER_DB_JOURNAL_FILENAME,
+                                                        NULL);
+               } else {
+                       filename_use = g_build_filename (data_location,
+                                                        TRACKER_DB_JOURNAL_FILENAME,
+                                                        NULL);
+               }
                filename_free = (gchar *) filename_use;
        } else {
                filename_use = filename;
diff --git a/src/libtracker-data/tracker-db-journal.h b/src/libtracker-data/tracker-db-journal.h
index d93efb8..f016409 100644
--- a/src/libtracker-data/tracker-db-journal.h
+++ b/src/libtracker-data/tracker-db-journal.h
@@ -60,6 +60,8 @@ GQuark       tracker_db_journal_error_quark                  (void);
  * Writer API
  */
 gboolean     tracker_db_journal_init                         (const gchar  *filename,
+                                                              const gchar  *cache_location,
+                                                              const gchar   *data_location,
                                                               gboolean      truncate,
                                                               GError      **error);
 gboolean     tracker_db_journal_shutdown                     (GError      **error);
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index c73f667..4f87172 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -156,9 +156,8 @@ static gboolean              locations_initialized;
 static gchar                *data_dir = NULL;
 static gchar                *user_data_dir = NULL;
 static gchar                *in_use_filename = NULL;
-static gchar                *in_use_loc = NULL;
-static gchar                *in_use_domain = NULL;
-static gchar                *in_use_ontology_name = NULL;
+static gchar                *in_use_cache_location = NULL;
+static gchar                *in_use_data_location = NULL;
 static gpointer              db_type_enum_class_pointer;
 static TrackerDBManagerFlags old_flags = 0;
 static guint                 s_cache_size;
@@ -666,7 +665,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 (in_use_loc, in_use_domain, in_use_ontology_name);
+               tracker_db_manager_init_locations (in_use_cache_location, in_use_data_location);
        }
 
        /* Get current collation locale */
@@ -795,7 +794,7 @@ db_recreate_all (GError **error)
 }
 
 void
-tracker_db_manager_init_locations (const char *loc, const gchar *domain, const char *ontology_name)
+tracker_db_manager_init_locations (const char *cache_location, const gchar *data_location)
 {
        const gchar *dir;
        guint i;
@@ -804,25 +803,25 @@ tracker_db_manager_init_locations (const char *loc, const gchar *domain, const c
                return;
        }
 
-       if (loc == NULL) {
-               loc = "tracker";
+       if (data_location == NULL) {
+               user_data_dir = g_build_filename (g_get_user_data_dir (),
+                                                 "tracker",
+                                                 "data",
+                                                 NULL);
+
+       } else {
+               user_data_dir = g_strdup (data_location);
        }
-       user_data_dir = g_build_filename (g_get_user_data_dir (),
-                                         loc,
-                                         "data",
-                                         NULL);
 
        /* For DISABLE_JOURNAL case we should use g_get_user_data_dir here. For now
         * keeping this as-is */
 
-       if (ontology_name == NULL) {
+       if (cache_location == NULL) {
                data_dir = g_build_filename (g_get_user_cache_dir (),
-                                            loc,
+                                            "tracker",
                                             NULL);
        } else {
-               data_dir = g_build_filename (g_get_user_cache_dir (),
-                                            loc, ontology_name,
-                                            NULL);
+               data_dir = g_strdup (cache_location);
        }
 
        for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
@@ -867,9 +866,8 @@ perform_recreate (gboolean *first_time, GError **error)
 
 static gboolean
 db_manager_init_unlocked (TrackerDBManagerFlags   flags,
-                          const gchar            *loc,
-                          const gchar            *domain,
-                          const gchar            *ontology_name,
+                          const gchar            *cache_location,
+                          const gchar            *data_location,
                           gboolean               *first_time,
                           gboolean                restoring_backup,
                           gboolean                shared_cache,
@@ -917,35 +915,31 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
 
        old_flags = flags;
 
-       g_free (in_use_filename);
-       g_free (in_use_loc);
-       g_free (in_use_domain);
-       g_free (in_use_ontology_name);
-
-       if (loc == NULL)
-               loc = "tracker";
-       in_use_loc = g_strdup (loc);
-
-       if (domain == NULL)
-               domain = "tracker";
-       in_use_domain = g_strdup (domain);
+       g_free (in_use_cache_location);
+       if (cache_location == NULL)
+               in_use_cache_location = NULL;
+       else
+               in_use_cache_location = g_strdup (cache_location);
 
-       if (ontology_name == NULL)
-               in_use_ontology_name = NULL;
+       g_free (in_use_data_location);
+       if (data_location == NULL)
+               in_use_data_location = NULL;
        else
-               in_use_ontology_name = g_strdup (ontology_name);
+               in_use_data_location = g_strdup (data_location);
+
+       tracker_db_manager_init_locations (cache_location, data_location);
 
-       tracker_db_manager_init_locations (loc, domain, ontology_name);
-       if (ontology_name == NULL) {
+       g_free (in_use_filename);
+       if (data_location == NULL) {
+               /* ~/.cache/tracker/data/ */
                in_use_filename = g_build_filename (g_get_user_data_dir (),
-                                                   loc,
+                                                   "tracker",
                                                    "data",
                                                    IN_USE_FILENAME,
                                                    NULL);
        } else {
-               in_use_filename = g_build_filename (g_get_user_data_dir (),
-                                                   loc, ontology_name,
-                                                   "data",
+               /* ~/.cache/cache_location/ontology-name/data/ */
+               in_use_filename = g_build_filename (data_location,
                                                    IN_USE_FILENAME,
                                                    NULL);
        }
@@ -1074,17 +1068,14 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                g_message ("Loading databases files...");
 
 #ifndef DISABLE_JOURNAL
-               if (ontology_name == NULL) {
+               if (data_location == NULL) {
                        journal_filename = g_build_filename (g_get_user_data_dir (),
-                                                            loc,
+                                                            "tracker",
                                                             "data",
                                                             TRACKER_DB_JOURNAL_FILENAME,
                                                             NULL);
                } else {
-                       journal_filename = g_build_filename (g_get_user_data_dir (),
-                                                            loc,
-                                                            ontology_name,
-                                                            "data",
+                       journal_filename = g_build_filename (data_location,
                                                             TRACKER_DB_JOURNAL_FILENAME,
                                                             NULL);
                }
@@ -1294,9 +1285,8 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
 
 gboolean
 tracker_db_manager_init (TrackerDBManagerFlags   flags,
-                         const gchar            *loc,
-                         const gchar            *domain,
-                         const gchar            *ontology_name,
+                         const gchar            *cache_location,
+                         const gchar            *data_location,
                          gboolean               *first_time,
                          gboolean                restoring_backup,
                          gboolean                shared_cache,
@@ -1311,7 +1301,7 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 
        g_mutex_lock (&init_mutex);
 
-       retval = db_manager_init_unlocked (flags, loc, domain, ontology_name,
+       retval = db_manager_init_unlocked (flags, cache_location, data_location,
                                           first_time, restoring_backup,
                                           shared_cache,
                                           select_cache_size, update_cache_size,
@@ -1566,8 +1556,13 @@ tracker_db_manager_has_enough_space  (void)
 inline static gchar *
 get_first_index_filename (void)
 {
-       return g_build_filename (g_get_user_cache_dir (),
-                                "tracker",
+       if (in_use_cache_location == NULL) {
+               return g_build_filename (g_get_user_cache_dir (),
+                                        "tracker",
+                                        FIRST_INDEX_FILENAME,
+                                        NULL);
+       }
+       return g_build_filename (in_use_cache_location,
                                 FIRST_INDEX_FILENAME,
                                 NULL);
 }
@@ -1638,8 +1633,13 @@ tracker_db_manager_set_first_index_done (gboolean done)
 inline static gchar *
 get_last_crawl_filename (void)
 {
-       return g_build_filename (g_get_user_cache_dir (),
-                                "tracker",
+       if (in_use_cache_location == NULL) {
+               return g_build_filename (g_get_user_cache_dir (),
+                                        "tracker",
+                                        LAST_CRAWL_FILENAME,
+                                        NULL);
+       }
+       return g_build_filename (in_use_cache_location,
                                 LAST_CRAWL_FILENAME,
                                 NULL);
 }
@@ -1722,8 +1722,13 @@ tracker_db_manager_set_last_crawl_done (gboolean done)
 inline static gchar *
 get_need_mtime_check_filename (void)
 {
-       return g_build_filename (g_get_user_cache_dir (),
-                                "tracker",
+       if (in_use_cache_location == NULL) {
+               return g_build_filename (g_get_user_cache_dir (),
+                                        "tracker",
+                                        NEED_MTIME_CHECK_FILENAME,
+                                        NULL);
+       }
+       return g_build_filename (in_use_cache_location,
                                 NEED_MTIME_CHECK_FILENAME,
                                 NULL);
 }
@@ -1812,8 +1817,13 @@ tracker_db_manager_set_need_mtime_check (gboolean needed)
 inline static gchar *
 get_parser_sha1_filename (void)
 {
-       return g_build_filename (g_get_user_cache_dir (),
-                                "tracker",
+       if (in_use_cache_location == NULL) {
+               return g_build_filename (g_get_user_cache_dir (),
+                                        "tracker",
+                                        PARSER_SHA1_FILENAME,
+                                        NULL);
+       }
+       return g_build_filename (in_use_cache_location,
                                 PARSER_SHA1_FILENAME,
                                 NULL);
 }
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 1df3e1c..a992773 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -53,9 +53,8 @@ typedef enum {
 
 GType               tracker_db_get_type                       (void) G_GNUC_CONST;
 gboolean            tracker_db_manager_init                   (TrackerDBManagerFlags   flags,
-                                                               const gchar            *loc,
-                                                               const gchar            *domain,
-                                                               const gchar            *ontology_name,
+                                                               const gchar            *cache_location,
+                                                               const gchar            *data_location,
                                                                gboolean               *first_time,
                                                                gboolean                restoring_backup,
                                                                gboolean                shared_cache,
@@ -70,9 +69,8 @@ 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         (const gchar           *loc,
-                                                               const gchar           *domain,
-                                                               const gchar           *ontology_name);
+void                tracker_db_manager_init_locations         (const gchar           *cache_location,
+                                                               const gchar           *data_location);
 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-backup.vala b/src/tracker-store/tracker-backup.vala
index ee6a4f8..4c1b2e8 100644
--- a/src/tracker-store/tracker-backup.vala
+++ b/src/tracker-store/tracker-backup.vala
@@ -84,7 +84,7 @@ public class Tracker.Backup : Object {
                        var notifier = (Status) (Tracker.DBus.get_object (typeof (Status)));
                        var busy_callback = notifier.get_callback ();
 
-                       // TODO: set loc, domain and ontology_name here from store session
+                       // TODO: set cache_location, data_location and ontology_location here from store 
session
                        Data.backup_restore (journal, null, null, null, null, busy_callback);
 
                        request.end ();
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index 95fd705..96bc03f 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -46,10 +46,12 @@ License which can be viewed at:
        static bool readonly_mode;
        static string domain_ontology;
        static string cache_location;
+       static string data_location;
+       static string ontology_location;
+       static string dbus_path;
        static string domain;
        static string ontology_name;
-       static string dbus_path;
-       
+
        const OptionEntry entries[] = {
                /* Daemon options */
                { "version", 'V', 0, OptionArg.NONE, ref version, N_("Displays version information"), null },
@@ -59,10 +61,12 @@ License which can be viewed at:
                { "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-ontology", 'd', 0, OptionArg.STRING, ref domain_ontology, N_("Load a specified 
domain ontology"), null },
-               { "cache-location", 'c', 0, OptionArg.STRING, ref cache_location, N_("Override cache location 
to be used"), null },
-               { "domain", 'm', 0, OptionArg.STRING, ref domain, N_("Override domain to be used"), null },
-               { "ontology-name", 'n', 0, OptionArg.STRING, ref ontology_name, N_("Override ontology to be 
used"), null },
+               { "domain", 'a', 0, OptionArg.STRING, ref domain, N_("Override domain to be used"), null },
+               { "ontology-name", 'o', 0, OptionArg.STRING, ref ontology_name, N_("Override ontology name to 
be used"), null },
                { "dbus-path", 'p', 0, OptionArg.STRING, ref dbus_path, N_("Override DBus path to be used"), 
null },
+               { "cache-location", 'c', 0, OptionArg.STRING, ref cache_location, N_("Override cache location 
to be used"), null },
+               { "data-location", 'm', 0, OptionArg.STRING, ref data_location, N_("Override data location to 
be used"), null },
+               { "ontology-location", 'n', 0, OptionArg.STRING, ref ontology_location, N_("Override ontology 
location to be used"), null },
 
                { null }
        };
@@ -78,13 +82,17 @@ License which can be viewed at:
                if (domain_ontology != null)
                        message ("  Domain ontology........................  %s", domain_ontology);
 
-               message ("  Cache location.........................  %s",
-                        cache_location != null ? cache_location : "tracker");
-               message ("  Domain ................................  %s",
-                        domain != null ? domain : "org.freedesktop.Tracker1");
-
+               if (domain != null)
+                       message ("  Domain.................................  %s", domain);
                if (ontology_name != null)
-                       message ("  Ontology name .........................  %s", ontology_name);
+                       message ("  Ontology name..........................  %s", ontology_name);
+
+               if (cache_location != null)
+                       message ("  Cache location.........................  %s", cache_location);
+               if (data_location != null)
+                       message ("  Data location..........................  %s", data_location);
+               if (ontology_location != null)
+                       message ("  Ontology location......................  %s", ontology_location);
        }
 
        static void do_shutdown () {
@@ -230,9 +238,9 @@ License which can be viewed at:
                                keyfile.load_from_file (keyfile_path, GLib.KeyFileFlags.NONE);
                                
                                try {
-                                       string? loaded_domain = keyfile.get_string ("DomainOntology", 
"Domain");
-                                       if (domain == null)
-                                               domain = loaded_domain;
+                                       string? loaded_data_location = keyfile.get_string ("DomainOntology", 
"DataLocation");
+                                       if (data_location == null)
+                                               data_location = loaded_data_location;
                                } catch (KeyFileError m) {}
 
                                try {
@@ -242,9 +250,9 @@ License which can be viewed at:
                                } catch (KeyFileError m) {}
 
                                try {
-                                       string? loaded_ontology_name = keyfile.get_string ("DomainOntology", 
"OntologyName");
-                                       if (ontology_name == null)
-                                               ontology_name = loaded_ontology_name;
+                                       string? loaded_ontology_location = keyfile.get_string 
("DomainOntology", "OntologyLocation");
+                                       if (ontology_location == null)
+                                               ontology_location = loaded_ontology_location;
                                } catch (KeyFileError m) {}
 
                                try {
@@ -253,6 +261,18 @@ License which can be viewed at:
                                                dbus_path = loaded_dbus_path;
                                } catch (KeyFileError m) {}
 
+                               try {
+                                       string? loaded_domain = keyfile.get_string ("DomainOntology", 
"Domain");
+                                       if (domain == null)
+                                               domain = loaded_domain;
+                               } catch (KeyFileError m) {}
+
+                               try {
+                                       string? loaded_ontology_name = keyfile.get_string ("DomainOntology", 
"OntologyName");
+                                       if (ontology_name == null)
+                                               ontology_name = loaded_ontology_name;
+                               } catch (KeyFileError m) {}
+
                        } catch (KeyFileError ke) {
                                critical("Loading " + keyfile_path + " " + ke.message);
                        } catch (FileError fe) {
@@ -325,7 +345,14 @@ License which can be viewed at:
                bool is_first_time_index;
 
                try {
-                       Tracker.Data.Manager.init (flags, cache_location, domain, ontology_name,
+                       string final_cache_location = cache_location != null ? cache_location.replace 
("%HOME%", Environment.get_home_dir()).replace("%SHAREDIR%", SHAREDIR) : null;
+                       string final_data_location = data_location != null ? data_location.replace ("%HOME%", 
Environment.get_home_dir()).replace("%SHAREDIR%", SHAREDIR) : null;
+                       string final_ontology_location = ontology_location != null ? 
ontology_location.replace ("%HOME%", Environment.get_home_dir()).replace("%SHAREDIR%", SHAREDIR) : null;
+                       
+                       Tracker.Data.Manager.init (flags,
+                                                  final_cache_location,
+                                                  final_data_location,
+                                                  final_ontology_location,
                                                   null,
                                                   out is_first_time_index,
                                                   true,
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index 29185c4..3eb9de7 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -292,7 +292,7 @@ reset_run (void)
 
                /* Clean up (select_cache_size and update_cache_size don't matter here) */
                if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL,
-                                             NULL, NULL, NULL, /* locl, domain and ontology-name */
+                                             NULL, NULL, /* cache_location, data_location */
                                              NULL,
                                              FALSE,
                                              FALSE,
@@ -309,7 +309,7 @@ reset_run (void)
                        return EXIT_FAILURE;
                }
 #ifndef DISABLE_JOURNAL
-               tracker_db_journal_init (NULL, FALSE, NULL);
+               tracker_db_journal_init (NULL, NULL, NULL, FALSE, NULL);
 #endif /* DISABLE_JOURNAL */
 
                tracker_db_manager_remove_all (hard_reset);
diff --git a/tests/libtracker-data/tracker-db-journal.c b/tests/libtracker-data/tracker-db-journal.c
index bea1813..a0e56f0 100644
--- a/tests/libtracker-data/tracker-db-journal.c
+++ b/tests/libtracker-data/tracker-db-journal.c
@@ -33,7 +33,7 @@ test_init_and_shutdown (void)
 
        /* check double init/shutdown */
        tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
-       result = tracker_db_journal_init (NULL, FALSE, &error);
+       result = tracker_db_journal_init (NULL, NULL, NULL, FALSE, &error);
        g_assert_no_error (error);
        g_assert (result == TRUE);
 
@@ -42,7 +42,7 @@ test_init_and_shutdown (void)
        g_assert (result == TRUE);
 
        tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
-       result = tracker_db_journal_init (NULL, FALSE, &error);
+       result = tracker_db_journal_init (NULL, NULL, NULL, FALSE, &error);
        g_assert_no_error (error);
        g_assert (result == TRUE);
 
@@ -64,7 +64,7 @@ test_write_functions (void)
        g_unlink (path);
 
        tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
-       tracker_db_journal_init (path, FALSE, &error);
+       tracker_db_journal_init (path, NULL, NULL, FALSE, &error);
        g_assert_no_error (error);
 
        filename = tracker_db_journal_get_filename ();



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