summaryrefslogtreecommitdiff
path: root/src/libtracker-data/tracker-db-manager.c
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2017-07-09 21:26:26 +0200
committerCarlos Garnacho <carlosg@gnome.org>2017-07-10 01:26:58 +0200
commit24489b72aca70748be7d5eeea7bd33889658af8d (patch)
tree1aca329de4c48cdf5efc224298db27e0a6c6c413 /src/libtracker-data/tracker-db-manager.c
parent9a3c29c185842c0231f739c782396b7eb427275b (diff)
downloadtracker-24489b72aca70748be7d5eeea7bd33889658af8d.tar.gz
libtracker-data: Make writable/wal interfaces unique
Instead of "picking" one of the several DB interfaces created, ensure canonical ones for these operations.
Diffstat (limited to 'src/libtracker-data/tracker-db-manager.c')
-rw-r--r--src/libtracker-data/tracker-db-manager.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 3ca253e64..b157e7645 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -96,6 +96,7 @@ typedef enum {
typedef struct {
TrackerDBInterface *iface;
+ TrackerDBInterface *wal_iface;
const gchar *file;
const gchar *name;
gchar *abs_filename;
@@ -107,7 +108,7 @@ typedef struct {
} TrackerDBDefinition;
static TrackerDBDefinition db_base = {
- NULL,
+ NULL, NULL,
"meta.db",
"meta",
NULL,
@@ -934,7 +935,7 @@ tracker_db_manager_optimize (TrackerDBManager *db_manager)
g_info (" Checking database is not in use");
- iface = tracker_db_manager_get_db_interface (db_manager);
+ iface = tracker_db_manager_get_writable_db_interface (db_manager);
/* Check if any connections are open? */
if (G_OBJECT (iface)->ref_count > 1) {
@@ -1050,6 +1051,44 @@ tracker_db_manager_get_db_interface (TrackerDBManager *db_manager)
return interface;
}
+static TrackerDBInterface *
+init_writable_db_interface (TrackerDBManager *db_manager)
+{
+ TrackerDBInterface *iface;
+ GError *error = NULL;
+ gboolean readonly;
+
+ /* Honor anyway the DBManager readonly flag */
+ readonly = (db_manager->flags & TRACKER_DB_MANAGER_READONLY) != 0;
+ iface = tracker_db_manager_create_db_interface (db_manager, readonly, &error);
+ if (error) {
+ g_critical ("Error opening readwrite database: %s", error->message);
+ g_error_free (error);
+ }
+
+ return iface;
+}
+
+TrackerDBInterface *
+tracker_db_manager_get_writable_db_interface (TrackerDBManager *db_manager)
+{
+ if (db_manager->db.iface == NULL) {
+ db_manager->db.iface = init_writable_db_interface (db_manager);
+ }
+
+ return db_manager->db.iface;
+}
+
+TrackerDBInterface *
+tracker_db_manager_get_wal_db_interface (TrackerDBManager *db_manager)
+{
+ if (db_manager->db.wal_iface == NULL) {
+ db_manager->db.wal_iface = init_writable_db_interface (db_manager);
+ }
+
+ return db_manager->db.wal_iface;
+}
+
/**
* tracker_db_manager_has_enough_space:
*