[tracker/checkpoint: 14/16] libtracker-data: Initialization of db during restore must be handled if fails



commit ebee7529ef379c80baafa0f31f734452f3476f10
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Jun 24 17:56:01 2011 +0200

    libtracker-data: Initialization of db during restore must be handled if fails
    
    In case the initialization of the db fails during the restore of a
    backup, and only in case of --disable-journal, then should the init
    fail with an error instead of trying to recreate a clean meta.db

 src/libtracker-data/libtracker-data.vapi           |    2 +-
 src/libtracker-data/tracker-data-backup.c          |   37 ++++++++++-----
 src/libtracker-data/tracker-data-manager.c         |    6 +++
 src/libtracker-data/tracker-data-manager.h         |    1 +
 src/libtracker-data/tracker-db-manager.c           |   47 ++++++++++++++-----
 src/libtracker-data/tracker-db-manager.h           |    1 +
 src/libtracker-direct/tracker-direct.vala          |    2 +-
 src/tracker-control/tracker-control-general.c      |    1 +
 src/tracker-store/tracker-main.vala                |    1 +
 tests/libtracker-data/tracker-backup-test.c        |    6 ++-
 .../libtracker-data/tracker-ontology-change-test.c |    6 ++-
 tests/libtracker-data/tracker-ontology-test.c      |    3 +
 tests/libtracker-data/tracker-sparql-blank-test.c  |    1 +
 tests/libtracker-data/tracker-sparql-test.c        |    3 +-
 tests/libtracker-fts/tracker-fts-test.c            |    3 +-
 utils/tracker-sql/tracker-sql.c                    |    1 +
 16 files changed, 87 insertions(+), 34 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index fe3b9b8..02e9b43 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -219,7 +219,7 @@ namespace Tracker {
 
 	[CCode (cheader_filename = "libtracker-data/tracker-data-manager.h")]
 	namespace Data.Manager {
-		public bool init (DBManagerFlags flags, [CCode (array_length = false)] string[]? test_schema, out bool first_time, bool journal_check, uint select_cache_size, uint update_cache_size, BusyCallback? busy_callback, string? busy_status) throws DBInterfaceError, DBJournalError;
+		public bool init (DBManagerFlags flags, [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 d2597ba..45c7eeb 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -611,6 +611,16 @@ tracker_data_backup_restore (GFile                *journal,
 
 		tracker_db_manager_init_locations ();
 
+		/* 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
+		 * or after a backup restoration). */
+		tracker_db_manager_create_version_file ();
+
+		/* Given we're radically changing the database, we
+		 * force a full mtime check against all known files in
+		 * the database for complete synchronisation. */
+		tracker_db_manager_set_need_mtime_check (TRUE);
+
 #ifndef DISABLE_JOURNAL
 		tracker_db_journal_init (NULL, FALSE, &n_error);
 
@@ -624,7 +634,6 @@ tracker_data_backup_restore (GFile                *journal,
 			}
 			n_error = NULL;
 		}
-#endif /* DISABLE_JOURNAL */
 
 		if (info->error) {
 			restore_from_temp ();
@@ -632,7 +641,6 @@ tracker_data_backup_restore (GFile                *journal,
 			remove_temp ();
 		}
 
-#ifndef DISABLE_JOURNAL
 		tracker_db_journal_shutdown (&n_error);
 
 		if (n_error) {
@@ -642,23 +650,26 @@ tracker_data_backup_restore (GFile                *journal,
 		}
 #endif /* DISABLE_JOURNAL */
 
-		tracker_data_manager_init (flags, test_schemas, &is_first, TRUE,
+		tracker_data_manager_init (flags, test_schemas, &is_first, TRUE, TRUE,
 		                           select_cache_size, update_cache_size,
 		                           busy_callback, busy_user_data,
 		                           "Restoring backup", &internal_error);
 
+#ifdef DISABLE_JOURNAL
 		if (internal_error) {
-			g_propagate_error (error, internal_error);
+			restore_from_temp ();
+
+			tracker_data_manager_init (flags, test_schemas, &is_first, TRUE, TRUE,
+			                           select_cache_size, update_cache_size,
+			                           busy_callback, busy_user_data,
+			                           "Restoring backup", &internal_error);
 		} else {
-			/* 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
-			 * or after a backup restoration). */
-			tracker_db_manager_create_version_file ();
-
-			/* Given we're radically changing the database, we
-			 * force a full mtime check against all known files in
-			 * the database for complete synchronisation. */
-			tracker_db_manager_set_need_mtime_check (TRUE);
+			remove_temp ();
+		}
+#endif /* DISABLE_JOURNAL */
+
+		if (internal_error) {
+			g_propagate_error (error, internal_error);
 		}
 	} else {
 		g_set_error (&info->error, TRACKER_DATA_BACKUP_ERROR,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 26acde9..3ad2213 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3408,6 +3408,7 @@ tracker_data_manager_reload (TrackerBusyCallback   busy_callback,
 	                                    NULL,
 	                                    &is_first,
 	                                    TRUE,
+	                                    FALSE,
 	                                    select_cache_size,
 	                                    update_cache_size,
 	                                    busy_callback,
@@ -3464,6 +3465,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                            const gchar           **test_schemas,
                            gboolean               *first_time,
                            gboolean                journal_check,
+                           gboolean                restoring_backup,
                            guint                   select_cache_size,
                            guint                   update_cache_size,
                            TrackerBusyCallback     busy_callback,
@@ -3508,6 +3510,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
 	if (!tracker_db_manager_init (flags,
 	                              &is_first_time_index,
+	                              restoring_backup,
 	                              FALSE,
 	                              select_cache_size,
 	                              update_cache_size,
@@ -3943,6 +3946,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 						                                  test_schemas,
 						                                  first_time,
 						                                  journal_check,
+						                                  restoring_backup,
 						                                  select_cache_size,
 						                                  update_cache_size,
 						                                  busy_callback,
@@ -4021,6 +4025,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 					                                  test_schemas,
 					                                  first_time,
 					                                  journal_check,
+					                                  restoring_backup,
 					                                  select_cache_size,
 					                                  update_cache_size,
 					                                  busy_callback,
@@ -4116,6 +4121,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 				                                  test_schemas,
 				                                  first_time,
 				                                  journal_check,
+				                                  restoring_backup,
 				                                  select_cache_size,
 				                                  update_cache_size,
 				                                  busy_callback,
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 4b4b0a0..6aa21ea 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -49,6 +49,7 @@ gboolean tracker_data_manager_init                   (TrackerDBManagerFlags   fl
                                                       const gchar           **test_schema,
                                                       gboolean               *first_time,
                                                       gboolean                journal_check,
+                                                      gboolean                restoring_backup,
                                                       guint                   select_cache_size,
                                                       guint                   update_cache_size,
                                                       TrackerBusyCallback     busy_callback,
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index faba4a7..d883d45 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -836,6 +836,7 @@ perform_recreate (gboolean *first_time, GError **error)
 gboolean
 tracker_db_manager_init (TrackerDBManagerFlags   flags,
                          gboolean               *first_time,
+                         gboolean                restoring_backup,
                          gboolean                shared_cache,
                          guint                   select_cache_size,
                          guint                   update_cache_size,
@@ -1080,7 +1081,14 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 				 * are only one byte in size even initually. */
 
 				if (size <= 1) {
-					must_recreate = TRUE;
+					if (!restoring_backup) {
+						must_recreate = TRUE;
+					} else {
+						g_set_error (&internal_error,
+						             TRACKER_DB_INTERFACE_ERROR,
+						             TRACKER_DB_OPEN_ERROR,
+						             "Corrupt db file");
+					}
 					continue;
 				}
 
@@ -1089,8 +1097,10 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 				if (internal_error) {
 					/* If this already doesn't succeed, then surely the file is
 					 * corrupt. No need to check for integrity anymore. */
-					g_clear_error (&internal_error);
-					must_recreate = TRUE;
+					if (!restoring_backup) {
+						g_clear_error (&internal_error);
+						must_recreate = TRUE;
+					}
 					continue;
 				}
 
@@ -1149,9 +1159,13 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 				                                              &internal_error,
 				                                              "SELECT 1 FROM Resource");
 				if (internal_error != NULL) {
-					must_recreate = TRUE;
-					g_error_free (internal_error);
-					internal_error = NULL;
+					if (!restoring_backup) {
+						must_recreate = TRUE;
+						g_error_free (internal_error);
+						internal_error = NULL;
+					} else {
+						continue;
+					}
 				} else {
 					g_object_unref (stmt);
 				}
@@ -1174,8 +1188,12 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 				return FALSE;
 			}
 			loaded = FALSE;
+		} else {
+			if (internal_error) {
+				g_propagate_error (error, internal_error);
+				return FALSE;
+			}
 		}
-
 	}
 
 	if (!loaded) {
@@ -1209,14 +1227,17 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 	}
 
 	if (internal_error) {
-		if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
-			perform_recreate (first_time, &internal_error);
-			if (!internal_error) {
+		if ((!restoring_backup) && (flags & TRACKER_DB_MANAGER_READONLY) == 0) {
+			GError *new_error = NULL;
+
+			perform_recreate (first_time, &new_error);
+			if (!new_error) {
 				resources_iface = tracker_db_manager_get_db_interfaces (&internal_error, 1,
 				                                                        TRACKER_DB_METADATA);
-			}
-			if (internal_error) {
-				g_propagate_error (error, internal_error);
+			} else {
+				/* Most serious error is the recreate one here */
+				g_clear_error (&internal_error);
+				g_propagate_error (error, new_error);
 				initialized = FALSE;
 				return FALSE;
 			}
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index af20ced..e012bbb 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -52,6 +52,7 @@ typedef enum {
 GType               tracker_db_get_type                       (void) G_GNUC_CONST;
 gboolean            tracker_db_manager_init                   (TrackerDBManagerFlags   flags,
                                                                gboolean               *first_time,
+                                                               gboolean                restoring_backup,
                                                                gboolean                shared_cache,
                                                                guint                   select_cache_size,
                                                                guint                   update_cache_size,
diff --git a/src/libtracker-direct/tracker-direct.vala b/src/libtracker-direct/tracker-direct.vala
index 55ed05e..2480848 100644
--- a/src/libtracker-direct/tracker-direct.vala
+++ b/src/libtracker-direct/tracker-direct.vala
@@ -33,7 +33,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
 					select_cache_size = int.parse (env_cache_size);
 				}
 
-				Data.Manager.init (DBManagerFlags.READONLY, null, null, false, select_cache_size, 0, null, null);
+				Data.Manager.init (DBManagerFlags.READONLY, null, null, false, false, select_cache_size, 0, null, null);
 			}
 
 			use_count++;
diff --git a/src/tracker-control/tracker-control-general.c b/src/tracker-control/tracker-control-general.c
index b597e88..a0b9c93 100644
--- a/src/tracker-control/tracker-control-general.c
+++ b/src/tracker-control/tracker-control-general.c
@@ -476,6 +476,7 @@ tracker_control_general_run (void)
 		if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL,
 		                              NULL,
 		                              FALSE,
+		                              FALSE,
 		                              100,
 		                              100,
 		                              NULL,
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index 768ed27..c8cf17b 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -278,6 +278,7 @@ License which can be viewed at:
 			                           null,
 			                           out is_first_time_index,
 			                           true,
+			                           false,
 			                           select_cache_size,
 			                           update_cache_size,
 			                           busy_callback,
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
index e806a02..f2a6006 100644
--- a/tests/libtracker-data/tracker-backup-test.c
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -112,7 +112,8 @@ test_backup_and_restore_helper (gboolean journal)
 
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
 	                           (const gchar **) test_schemas,
-	                           NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+	                           NULL, FALSE, FALSE,
+	                           100, 100, NULL, NULL, NULL, &error);
 
 	g_assert_no_error (error);
 
@@ -175,7 +176,8 @@ test_backup_and_restore_helper (gboolean journal)
 
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
 	                           (const gchar **) test_schemas,
-	                           NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+	                           NULL, FALSE, FALSE,
+	                           100, 100, NULL, NULL, NULL, &error);
 
 	g_assert_no_error (error);
 
diff --git a/tests/libtracker-data/tracker-ontology-change-test.c b/tests/libtracker-data/tracker-ontology-change-test.c
index 2fd935d..355a93f 100644
--- a/tests/libtracker-data/tracker-ontology-change-test.c
+++ b/tests/libtracker-data/tracker-ontology-change-test.c
@@ -229,7 +229,8 @@ test_ontology_change (void)
 		g_chmod (ontology_file, 0666);
 
 		tracker_data_manager_init (0, (const gchar **) test_schemas,
-		                           NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+		                           NULL, FALSE, FALSE,
+		                           100, 100, NULL, NULL, NULL, &error);
 
 		g_assert_no_error (error);
 
@@ -272,7 +273,8 @@ test_ontology_change (void)
 	delete_db (FALSE);
 
 	tracker_data_manager_init (0, (const gchar **) test_schemas,
-	                           NULL, TRUE, 100, 100, NULL, NULL, NULL, &error);
+	                           NULL, TRUE, FALSE,
+	                           100, 100, NULL, NULL, NULL, &error);
 
 	g_assert_no_error (error);
 
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index 8910465..98165f1 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -181,6 +181,7 @@ test_ontology_init (void)
 	                           NULL,
 	                           NULL,
 	                           FALSE,
+	                           FALSE,
 	                           100,
 	                           100,
 	                           NULL,
@@ -199,6 +200,7 @@ test_ontology_init (void)
 	                           NULL,
 	                           NULL,
 	                           FALSE,
+	                           FALSE,
 	                           100,
 	                           100,
 	                           NULL,
@@ -237,6 +239,7 @@ test_query (gconstpointer test_data)
 	                           NULL,
 	                           NULL,
 	                           FALSE,
+	                           FALSE,
 	                           100,
 	                           100,
 	                           NULL,
diff --git a/tests/libtracker-data/tracker-sparql-blank-test.c b/tests/libtracker-data/tracker-sparql-blank-test.c
index 9406684..7fef14d 100644
--- a/tests/libtracker-data/tracker-sparql-blank-test.c
+++ b/tests/libtracker-data/tracker-sparql-blank-test.c
@@ -49,6 +49,7 @@ test_blank (void)
 	                           NULL,
 	                           NULL,
 	                           FALSE,
+	                           FALSE,
 	                           100,
 	                           100,
 	                           NULL,
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index e95f140..96dbaaa 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -242,7 +242,8 @@ test_sparql_query (gconstpointer test_data)
 
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
 	                           test_schemas,
-	                           NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+	                           NULL, FALSE, FALSE,
+	                           100, 100, NULL, NULL, NULL, &error);
 
 	g_assert_no_error (error);
 
diff --git a/tests/libtracker-fts/tracker-fts-test.c b/tests/libtracker-fts/tracker-fts-test.c
index a54e45a..fb086ae 100644
--- a/tests/libtracker-fts/tracker-fts-test.c
+++ b/tests/libtracker-fts/tracker-fts-test.c
@@ -74,7 +74,8 @@ test_sparql_query (gconstpointer test_data)
 	tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
 	                           test_schemas,
-	                           NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+	                           NULL, FALSE, FALSE,
+	                           100, 100, NULL, NULL, NULL, &error);
 
 	g_assert_no_error (error);
 
diff --git a/utils/tracker-sql/tracker-sql.c b/utils/tracker-sql/tracker-sql.c
index db5416b..43eb6d4 100644
--- a/utils/tracker-sql/tracker-sql.c
+++ b/utils/tracker-sql/tracker-sql.c
@@ -134,6 +134,7 @@ main (int argc, char **argv)
 		                                NULL,
 		                                &first_time,
 		                                FALSE,
+		                                FALSE,
 		                                100,
 		                                100,
 		                                NULL,



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