Commit 79ad6802 authored by Philip Van Hoof's avatar Philip Van Hoof Committed by Jürg Billeter

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
parent 44ca01c2
......@@ -226,7 +226,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 ();
}
......
......@@ -608,6 +608,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);
......@@ -621,7 +631,6 @@ tracker_data_backup_restore (GFile *journal,
}
n_error = NULL;
}
#endif /* DISABLE_JOURNAL */
if (info->error) {
restore_from_temp ();
......@@ -629,7 +638,6 @@ tracker_data_backup_restore (GFile *journal,
remove_temp ();
}
#ifndef DISABLE_JOURNAL
tracker_db_journal_shutdown (&n_error);
if (n_error) {
......@@ -639,23 +647,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,
......
......@@ -3405,6 +3405,7 @@ tracker_data_manager_reload (TrackerBusyCallback busy_callback,
NULL,
&is_first,
TRUE,
FALSE,
select_cache_size,
update_cache_size,
busy_callback,
......@@ -3461,6 +3462,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,
......@@ -3505,6 +3507,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,
......@@ -4023,6 +4026,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
test_schemas,
first_time,
journal_check,
restoring_backup,
select_cache_size,
update_cache_size,
busy_callback,
......@@ -4121,6 +4125,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
test_schemas,
first_time,
journal_check,
restoring_backup,
select_cache_size,
update_cache_size,
busy_callback,
......@@ -4227,6 +4232,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
test_schemas,
first_time,
journal_check,
restoring_backup,
select_cache_size,
update_cache_size,
busy_callback,
......
......@@ -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,
......
......@@ -835,6 +835,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,
......@@ -1062,7 +1063,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;
}
......@@ -1071,8 +1079,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;
}
......@@ -1129,9 +1139,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);
}
......@@ -1150,8 +1164,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) {
......@@ -1185,14 +1203,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;
}
......
......@@ -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,
......
......@@ -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++;
......
......@@ -472,6 +472,7 @@ tracker_control_general_run (void)
if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL,
NULL,
FALSE,
FALSE,
100,
100,
NULL,
......
......@@ -272,6 +272,7 @@ License which can be viewed at:
null,
out is_first_time_index,
true,
false,
select_cache_size,
update_cache_size,
busy_callback,
......
......@@ -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);
......@@ -171,7 +172,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);
......
......@@ -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);
......
......@@ -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,
......
......@@ -49,6 +49,7 @@ test_blank (void)
NULL,
NULL,
FALSE,
FALSE,
100,
100,
NULL,
......
......@@ -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);
......
......@@ -75,7 +75,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);
......
......@@ -134,6 +134,7 @@ main (int argc, char **argv)
NULL,
&first_time,
FALSE,
FALSE,
100,
100,
NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment