[tracker: 1/8] tracker-db-manager: add "first_time" field




commit ed65749e0e4ce3d13397f74fb212920d97c93418
Author: Abanoub Ghadban <abanoub gdb gmail com>
Date:   Wed Aug 4 12:11:29 2021 +0200

    tracker-db-manager: add "first_time" field
    
    Adds "first_time" field to TrackerDBManager class.
    Removes "first_time" argument from tracker_db_manager_new() as we can access it through 
tracker_db_manager_is_first_time()
    Later, the first_time field will be checked before deleting the newly created db when error occures 
during the creation process

 src/libtracker-data/tracker-data-manager.c |  3 ++-
 src/libtracker-data/tracker-db-manager.c   | 32 ++++++++++++++++--------------
 src/libtracker-data/tracker-db-manager.h   |  3 ++-
 src/tracker/tracker-export.c               |  3 +--
 4 files changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index fce5b44cc..391ac6d79 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3810,7 +3810,6 @@ tracker_data_manager_initable_init (GInitable     *initable,
 
        manager->db_manager = tracker_db_manager_new (manager->flags,
                                                      manager->cache_location,
-                                                     &is_create,
                                                      FALSE,
                                                      manager->select_cache_size,
                                                      manager->update_cache_size,
@@ -3823,6 +3822,8 @@ tracker_data_manager_initable_init (GInitable     *initable,
                return FALSE;
        }
 
+       is_create = tracker_db_manager_is_first_time (manager->db_manager);
+
        g_signal_connect (manager->db_manager, "setup-interface",
                          G_CALLBACK (setup_interface_cb), manager);
        g_signal_connect (manager->db_manager, "update-interface",
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 8485af62e..26d38fe19 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -128,6 +128,7 @@ struct _TrackerDBManager {
        TrackerDBManagerFlags flags;
        guint s_cache_size;
        guint u_cache_size;
+       gboolean first_time;
 
        gpointer vtab_data;
 
@@ -152,6 +153,12 @@ static TrackerDBInterface *tracker_db_manager_create_db_interface   (TrackerDBMa
 
 static TrackerDBInterface * init_writable_db_interface              (TrackerDBManager *db_manager);
 
+gboolean
+tracker_db_manager_is_first_time (TrackerDBManager *db_manager)
+{
+       return db_manager->first_time;
+}
+
 TrackerDBManagerFlags
 tracker_db_manager_get_flags (TrackerDBManager *db_manager,
                               guint            *select_cache_size,
@@ -513,16 +520,15 @@ db_check_integrity (TrackerDBManager *db_manager)
 
 TrackerDBManager *
 tracker_db_manager_new (TrackerDBManagerFlags   flags,
-                       GFile                  *cache_location,
-                       gboolean               *first_time,
-                       gboolean                shared_cache,
-                       guint                   select_cache_size,
-                       guint                   update_cache_size,
-                       TrackerBusyCallback     busy_callback,
-                       gpointer                busy_user_data,
+                        GFile                  *cache_location,
+                        gboolean                shared_cache,
+                        guint                   select_cache_size,
+                        guint                   update_cache_size,
+                        TrackerBusyCallback     busy_callback,
+                        gpointer                busy_user_data,
                         GObject                *iface_data,
                         gpointer                vtab_data,
-                       GError                **error)
+                        GError                **error)
 {
        TrackerDBManager *db_manager;
        TrackerDBVersion version;
@@ -534,10 +540,8 @@ tracker_db_manager_new (TrackerDBManagerFlags   flags,
        db_manager = g_object_new (TRACKER_TYPE_DB_MANAGER, NULL);
        db_manager->vtab_data = vtab_data;
 
-       /* First set defaults for return values */
-       if (first_time) {
-               *first_time = FALSE;
-       }
+       /* Set default value for first_time */
+       db_manager->first_time = FALSE;
 
        /* Set up locations */
        db_manager->flags = flags;
@@ -618,9 +622,7 @@ tracker_db_manager_new (TrackerDBManagerFlags   flags,
        }
 
        if (need_to_create) {
-               if (first_time) {
-                       *first_time = TRUE;
-               }
+               db_manager->first_time = TRUE;
 
                if ((db_manager->flags & TRACKER_DB_MANAGER_IN_MEMORY) == 0 &&
                     !tracker_file_system_has_enough_space (db_manager->data_dir, 
TRACKER_DB_MIN_REQUIRED_SPACE, TRUE)) {
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index b8fd04aa4..3147fda4c 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -54,7 +54,6 @@ gboolean            tracker_db_manager_db_exists              (GFile *cache_loca
 
 TrackerDBManager   *tracker_db_manager_new                    (TrackerDBManagerFlags   flags,
                                                                GFile                  *cache_location,
-                                                               gboolean               *first_time,
                                                                gboolean                shared_cache,
                                                                guint                   select_cache_size,
                                                                guint                   update_cache_size,
@@ -69,6 +68,8 @@ TrackerDBInterface *tracker_db_manager_get_writable_db_interface (TrackerDBManag
 
 gboolean            tracker_db_manager_has_enough_space       (TrackerDBManager      *db_manager);
 
+gboolean            tracker_db_manager_is_first_time          (TrackerDBManager      *db_manager);
+
 TrackerDBManagerFlags
                     tracker_db_manager_get_flags              (TrackerDBManager      *db_manager,
                                                               guint                 *select_cache_size,
diff --git a/src/tracker/tracker-export.c b/src/tracker/tracker-export.c
index ead5de036..38c05f941 100644
--- a/src/tracker/tracker-export.c
+++ b/src/tracker/tracker-export.c
@@ -390,8 +390,7 @@ export_2to3_with_query (const gchar  *query,
 
        db_manager = tracker_db_manager_new (TRACKER_DB_MANAGER_READONLY |
                                             TRACKER_DB_MANAGER_SKIP_VERSION_CHECK,
-                                            store,
-                                            NULL, FALSE,
+                                            store, FALSE,
                                             1, 1, NULL, NULL, NULL, NULL, &inner_error);
 
        if (inner_error) {


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