[tracker: 2/8] delete the half-completed db if the db creation failed
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker: 2/8] delete the half-completed db if the db creation failed
- Date: Thu, 12 Aug 2021 15:02:24 +0000 (UTC)
commit 255123acfafadf5f23c5322264d375ca2ece37b2
Author: Abanoub Ghadban <abanoub gdb gmail com>
Date: Wed Aug 4 12:15:48 2021 +0200
delete the half-completed db if the db creation failed
Prevents saving half completed database when the error happens while creating the database for the first
time.
src/libtracker-data/tracker-data-manager.c | 19 ++++++++++++-------
src/libtracker-data/tracker-db-manager.c | 23 +++++++++++++++++++++++
src/libtracker-data/tracker-db-manager.h | 3 +++
3 files changed, 38 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 391ac6d79..6d3892b8e 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3888,12 +3888,12 @@ tracker_data_manager_initable_init (GInitable *initable,
NULL,
NULL,
&ontology_error);
+ g_free (uri);
+
if (ontology_error) {
g_propagate_error (error, ontology_error);
- return FALSE;
+ goto rollback_newly_created_db;
}
-
- g_free (uri);
}
tracker_data_ontology_setup_db (manager, iface, "main", FALSE,
@@ -3907,18 +3907,18 @@ tracker_data_manager_initable_init (GInitable *initable,
if (internal_error) {
g_propagate_error (error, internal_error);
- return FALSE;
+ goto rollback_newly_created_db;
}
if (!tracker_data_manager_init_fts (manager, iface, "main", TRUE, &internal_error)) {
g_propagate_error (error, internal_error);
- return FALSE;
+ goto rollback_newly_created_db;
}
tracker_data_manager_initialize_iface (manager, iface, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
- return FALSE;
+ goto rollback_newly_created_db;
}
/* store ontology in database */
@@ -3930,7 +3930,7 @@ tracker_data_manager_initable_init (GInitable *initable,
if (internal_error) {
g_propagate_error (error, internal_error);
- return FALSE;
+ goto rollback_newly_created_db;
}
write_ontologies_gvdb (manager, TRUE /* overwrite */, NULL);
@@ -4399,6 +4399,11 @@ skip_ontology_check:
tracker_data_manager_update_status (manager, "Idle");
return TRUE;
+
+rollback_newly_created_db:
+ tracker_data_rollback_transaction (manager->data_update);
+ tracker_db_manager_rollback_db_creation (manager->db_manager, NULL);
+ return FALSE;
}
static gboolean
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 26d38fe19..63a7989b0 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -463,6 +463,29 @@ tracker_db_manager_db_exists (GFile *cache_location)
return db_exists;
}
+int
+tracker_db_manager_rollback_db_creation (TrackerDBManager *db_manager,
+ GError **error)
+{
+ gchar *dir;
+ gchar *filename;
+ int ret;
+
+ g_return_val_if_fail (db_manager->first_time, -1);
+
+ if ((db_manager->flags & TRACKER_DB_MANAGER_IN_MEMORY) != 0)
+ return 0;
+
+ dir = g_file_get_path (db_manager->cache_location);
+ filename = g_build_filename (dir, db_base.file, NULL);
+
+ ret = g_unlink (filename);
+
+ g_free (dir);
+ g_free (filename);
+ return ret;
+}
+
static gboolean
db_check_integrity (TrackerDBManager *db_manager)
{
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 3147fda4c..62bf3b944 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -50,6 +50,9 @@ typedef enum {
TRACKER_DB_MANAGER_SKIP_VERSION_CHECK = 1 << 9,
} TrackerDBManagerFlags;
+int tracker_db_manager_rollback_db_creation (TrackerDBManager *db_manager,
+ GError **error);
+
gboolean tracker_db_manager_db_exists (GFile *cache_location);
TrackerDBManager *tracker_db_manager_new (TrackerDBManagerFlags flags,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]