[tracker/binary-log-2: 18/23] Reimplemented backup and restore support



commit 92a4f60630215ac049190d3352c635aa3a08a1fa
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Jan 4 11:19:30 2010 +0100

    Reimplemented backup and restore support

 data/dbus/tracker-backup.xml                    |    2 -
 src/libtracker-data/tracker-data-backup.c       |  134 +++++++++++++-
 src/libtracker-data/tracker-data-backup.h       |    7 +-
 src/libtracker-db/tracker-db-interface-sqlite.c |   24 ---
 src/libtracker-db/tracker-db-interface.c        |   15 --
 src/libtracker-db/tracker-db-interface.h        |    4 -
 src/libtracker-db/tracker-db-manager.c          |  225 ++++++++++++++++-------
 src/libtracker-db/tracker-db-manager.h          |   27 ++-
 src/tracker-store/tracker-backup.c              |   72 ++------
 src/tracker-store/tracker-backup.h              |    2 -
 10 files changed, 315 insertions(+), 197 deletions(-)
---
diff --git a/data/dbus/tracker-backup.xml b/data/dbus/tracker-backup.xml
index 44f93f0..d079eee 100644
--- a/data/dbus/tracker-backup.xml
+++ b/data/dbus/tracker-backup.xml
@@ -5,11 +5,9 @@
     <method name="Save">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="s" name="destination-uri" direction="in" />
-      <arg type="s" name="journal-uri" direction="in" />
     </method>
     <method name="Restore">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
-      <arg type="s" name="backup-uri" direction="in" />
       <arg type="s" name="journal-uri" direction="in" />
     </method>
   </interface>
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index ee1c4fe..869fb54 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -24,34 +24,152 @@
 
 #include <libtracker-db/tracker-db-manager.h>
 #include <libtracker-db/tracker-db-journal.h>
+#include <libtracker-data/tracker-data-manager.h>
 
 #include "tracker-data-backup.h"
 
+typedef struct {
+	GFile *destination, *journal;
+	TrackerDataBackupFinished callback;
+	gpointer user_data;
+	GDestroyNotify destroy;
+	GError *error;
+} BackupSaveInfo;
+
 GQuark
 tracker_data_backup_error_quark (void)
 {
-	return g_quark_from_static_string ("tracker-data-backup-error-quark");
+	return g_quark_from_static_string (TRACKER_DATA_BACKUP_ERROR_DOMAIN);
+}
+
+static void
+free_backup_save_info (BackupSaveInfo *info)
+{
+	if (info->destination) {
+		g_object_unref (info->destination);
+	}
+
+	if (info->journal) {
+		g_object_unref (info->journal);
+	}
+
+	if (info->destroy) {
+		info->destroy (info->user_data);
+	}
+
+	g_clear_error (&info->error);
+
+	g_free (info);
+}
+
+static void
+on_journal_copied (GObject *source_object,
+                   GAsyncResult *res,
+                   gpointer user_data)
+{
+	BackupSaveInfo *info = user_data;
+	GError *error = NULL;
+
+	g_file_copy_finish (info->journal, res, &error);
+
+	if (info->callback) {
+		info->callback (error, info->user_data);
+	}
+
+	free_backup_save_info (info);
+
+	g_clear_error (&error);
 }
 
 void
 tracker_data_backup_save (GFile *destination,
-                          GFile *journal,
                           TrackerDataBackupFinished callback,
                           gpointer user_data,
                           GDestroyNotify destroy)
 {
-	// TODO: Unimplemented
-	g_critical ("tracker_data_backup_save unimplemented");
+	BackupSaveInfo *info;
+
+	info = g_new0 (BackupSaveInfo, 1);
+	info->destination = g_object_ref (destination);
+	info->journal = g_file_new_for_path (tracker_db_journal_get_filename ());
+	info->callback = callback;
+	info->user_data = user_data;
+	info->destroy = destroy;
+
+	/* It's fine to copy this asynchronous: the journal replay code can or 
+	 * should cope with unfinished entries at the end of the file, while
+	 * restoring a backup made this way. */
+
+	g_file_copy_async (info->journal, info->destination,
+	                   G_FILE_COPY_OVERWRITE,
+	                   G_PRIORITY_HIGH,
+	                   NULL, NULL, NULL,
+	                   on_journal_copied,
+	                   info);
+}
+
+static gboolean
+on_restore_done (gpointer user_data)
+{
+	BackupSaveInfo *info = user_data;
+
+	if (info->callback) {
+		info->callback (info->error, info->user_data);
+	}
+
+	free_backup_save_info (info);
+
+	return FALSE;
 }
 
 void
-tracker_data_backup_restore (GFile *backup,
-                             GFile *journal,
+tracker_data_backup_restore (GFile *journal,
                              TrackerDataBackupFinished callback,
                              gpointer user_data,
                              GDestroyNotify destroy)
 {
-	// TODO: Unimplemented
-	g_critical ("tracker_data_backup_restore");
+	BackupSaveInfo *info;
+
+	info = g_new0 (BackupSaveInfo, 1);
+	info->destination = g_file_new_for_path (tracker_db_journal_get_filename ());
+	info->journal = g_object_ref (journal);
+	info->callback = callback;
+	info->user_data = user_data;
+	info->destroy = destroy;
+
+	if (g_file_query_exists (info->journal, NULL)) {
+		TrackerDBManagerFlags flags = tracker_db_manager_get_flags ();
+		gboolean is_first;
+
+		tracker_db_manager_move_to_temp ();
+		tracker_data_manager_shutdown ();
+
+		/* Synchronous: we don't want the mainloop to run while copying the
+		 * journal, as nobody should be writing anything at this point */
+
+		g_file_copy (info->journal, info->destination,
+		             G_FILE_COPY_OVERWRITE,
+		             NULL, NULL, NULL,
+		             &info->error);
+
+		tracker_db_manager_init_locations ();
+		tracker_db_journal_init (NULL);
+
+		if (info->error) {
+			tracker_db_manager_restore_from_temp ();
+		} else {
+			tracker_db_manager_remove_temp ();
+		}
+
+		tracker_db_journal_shutdown ();
+
+		tracker_data_manager_init (flags, NULL, &is_first);
+
+	} else {
+		g_set_error (&info->error, TRACKER_DATA_BACKUP_ERROR, 0, 
+		             "Backup file doesn't exist");
+	}
+
+	g_idle_add (on_restore_done, info);
 }
 
diff --git a/src/libtracker-data/tracker-data-backup.h b/src/libtracker-data/tracker-data-backup.h
index 5941dd0..8dc4acf 100644
--- a/src/libtracker-data/tracker-data-backup.h
+++ b/src/libtracker-data/tracker-data-backup.h
@@ -30,16 +30,17 @@ G_BEGIN_DECLS
 #error "only <libtracker-data/tracker-data.h> must be included directly."
 #endif
 
+#define TRACKER_DATA_BACKUP_ERROR_DOMAIN "TrackerBackup"
+#define TRACKER_DATA_BACKUP_ERROR        tracker_data_backup_error_quark()
+
 typedef void (*TrackerDataBackupFinished) (GError *error, gpointer user_data);
 
 GQuark tracker_data_backup_error_quark (void);
 void   tracker_data_backup_save        (GFile                     *destination,
-                                        GFile                     *journal,
                                         TrackerDataBackupFinished  callback,
                                         gpointer                   user_data,
                                         GDestroyNotify             destroy);
-void   tracker_data_backup_restore     (GFile                     *backup,
-                                        GFile                     *journal,
+void   tracker_data_backup_restore     (GFile                     *journal,
                                         TrackerDataBackupFinished  callback,
                                         gpointer                   user_data,
                                         GDestroyNotify             destroy);
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index 144c20d..5420e32 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -125,8 +125,6 @@ static GType tracker_db_statement_sqlite_get_type (void);
 static void tracker_db_interface_sqlite_iface_init (TrackerDBInterfaceIface *iface);
 static void tracker_db_statement_sqlite_iface_init (TrackerDBStatementIface *iface);
 static void tracker_db_cursor_sqlite_iface_init (TrackerDBCursorIface *iface);
-static void tracker_db_interface_sqlite_disconnect (TrackerDBInterface *db_interface);
-static void tracker_db_interface_sqlite_reconnect  (TrackerDBInterface *db_interface);
 
 static TrackerDBStatementSqlite * tracker_db_statement_sqlite_new (TrackerDBInterfaceSqlite     *db_interface,
                                                                    sqlite3_stmt                         *sqlite_stmt);
@@ -754,8 +752,6 @@ tracker_db_interface_sqlite_iface_init (TrackerDBInterfaceIface *iface)
 {
 	iface->create_statement = tracker_db_interface_sqlite_create_statement;
 	iface->execute_query = tracker_db_interface_sqlite_execute_query;
-	iface->disconnect  = tracker_db_interface_sqlite_disconnect;
-	iface->reconnect  = tracker_db_interface_sqlite_reconnect;
 }
 
 TrackerDBInterface *
@@ -1156,26 +1152,6 @@ tracker_db_cursor_sqlite_get_string (TrackerDBCursor *cursor,  guint column)
 	return (const gchar *) sqlite3_column_text (priv->stmt, column);
 }
 
-static void
-tracker_db_interface_sqlite_disconnect (TrackerDBInterface *db_interface)
-{
-	TrackerDBInterfaceSqlitePrivate *priv;
-
-	priv = TRACKER_DB_INTERFACE_SQLITE_GET_PRIVATE (db_interface);
-
-	close_database (priv);
-}
-
-static void
-tracker_db_interface_sqlite_reconnect (TrackerDBInterface *db_interface)
-{
-	TrackerDBInterfaceSqlitePrivate *priv;
-
-	priv = TRACKER_DB_INTERFACE_SQLITE_GET_PRIVATE (db_interface);
-
-	open_database (priv);
-	prepare_database (priv);
-}
 
 static TrackerDBResultSet *
 tracker_db_statement_sqlite_execute (TrackerDBStatement                  *stmt,
diff --git a/src/libtracker-db/tracker-db-interface.c b/src/libtracker-db/tracker-db-interface.c
index db296b2..881c9e7 100644
--- a/src/libtracker-db/tracker-db-interface.c
+++ b/src/libtracker-db/tracker-db-interface.c
@@ -390,21 +390,6 @@ tracker_db_interface_end_transaction (TrackerDBInterface *interface)
 	return TRUE;
 }
 
-void
-tracker_db_interface_disconnect (TrackerDBInterface  *interface)
-{
-	g_return_if_fail (TRACKER_IS_DB_INTERFACE (interface));
-
-	TRACKER_DB_INTERFACE_GET_IFACE (interface)->disconnect (interface);
-}
-
-void
-tracker_db_interface_reconnect (TrackerDBInterface  *interface)
-{
-	g_return_if_fail (TRACKER_IS_DB_INTERFACE (interface));
-
-	TRACKER_DB_INTERFACE_GET_IFACE (interface)->reconnect (interface);
-}
 
 void
 tracker_db_statement_bind_double (TrackerDBStatement    *stmt,
diff --git a/src/libtracker-db/tracker-db-interface.h b/src/libtracker-db/tracker-db-interface.h
index 7c466a8..7b38b73 100644
--- a/src/libtracker-db/tracker-db-interface.h
+++ b/src/libtracker-db/tracker-db-interface.h
@@ -76,8 +76,6 @@ struct TrackerDBInterfaceIface {
 	TrackerDBResultSet * (* execute_query)    (TrackerDBInterface  *interface,
 	                                           GError             **error,
 	                                           const gchar         *query);
-	void                 (* disconnect)       (TrackerDBInterface  *interface);
-	void                 (* reconnect)        (TrackerDBInterface  *interface);
 };
 
 struct TrackerDBStatementIface {
@@ -157,8 +155,6 @@ TrackerDBResultSet *tracker_db_interface_execute_query     (TrackerDBInterface
 
 gboolean            tracker_db_interface_start_transaction (TrackerDBInterface  *interface);
 gboolean            tracker_db_interface_end_transaction   (TrackerDBInterface  *interface);
-void                tracker_db_interface_disconnect        (TrackerDBInterface  *interface);
-void                tracker_db_interface_reconnect         (TrackerDBInterface  *interface);
 void                tracker_db_statement_bind_double       (TrackerDBStatement  *stmt,
                                                             int                  index,
                                                             double               value);
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index b1607d7..8ace824 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -146,20 +146,22 @@ static TrackerDBDefinition dbs[] = {
 	  0 },
 };
 
-static gboolean                    db_exec_no_reply    (TrackerDBInterface *iface,
-                                                        const gchar        *query,
-                                                        ...);
+static gboolean            db_exec_no_reply    (TrackerDBInterface *iface,
+                                                const gchar        *query,
+                                                ...);
 static TrackerDBInterface *db_interface_create (TrackerDB           db);
 static TrackerDBInterface *tracker_db_manager_get_db_interfaces     (gint num, ...);
 static TrackerDBInterface *tracker_db_manager_get_db_interfaces_ro  (gint num, ...);
 
-static gboolean                    initialized;
-static gchar              *sql_dir;
-static gchar              *data_dir;
-static gchar              *user_data_dir;
-static gchar              *sys_tmp_dir;
-static gpointer                    db_type_enum_class_pointer;
-static TrackerDBInterface *resources_iface;
+static gboolean              initialized;
+static gboolean              locations_initialized;
+static gchar                *sql_dir;
+static gchar                *data_dir = NULL;
+static gchar                *user_data_dir = NULL;
+static gchar                *sys_tmp_dir = NULL;
+static gpointer              db_type_enum_class_pointer;
+static TrackerDBInterface   *resources_iface;
+static TrackerDBManagerFlags old_flags = 0;
 
 static const gchar *
 location_to_directory (TrackerDBLocation location)
@@ -297,6 +299,12 @@ function_regexp (TrackerDBInterface *interface,
 	return result;
 }
 
+TrackerDBManagerFlags
+tracker_db_manager_get_flags (void)
+{
+	return old_flags;
+}
+
 static void
 function_group_concat_step (TrackerDBInterface *interface,
                             void               *aggregate_context,
@@ -847,7 +855,7 @@ db_interface_create (TrackerDB db)
 }
 
 static void
-db_manager_remove_all (gboolean rm_backup_and_log, gboolean not_meta)
+db_manager_remove_all (gboolean rm_journal)
 {
 	guint i;
 
@@ -858,16 +866,12 @@ db_manager_remove_all (gboolean rm_backup_and_log, gboolean not_meta)
 	 */
 	for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
 
-		if (not_meta && i == TRACKER_DB_METADATA) {
-			continue;
-		}
-
 		g_message ("  Removing database:'%s'",
 		           dbs[i].abs_filename);
 		g_unlink (dbs[i].abs_filename);
 	}
 
-	if (rm_backup_and_log) {
+	if (rm_journal) {
 		GFile *file;
 		gchar *cpath;
 
@@ -1057,6 +1061,38 @@ db_recreate_all (void)
 	}
 }
 
+void
+tracker_db_manager_init_locations (void)
+{
+	const gchar *dir;
+	guint i;
+	gchar *filename;
+
+	filename = g_strdup_printf ("tracker-%s", g_get_user_name ());
+	sys_tmp_dir = g_build_filename (g_get_tmp_dir (), filename, NULL);
+	g_free (filename);
+
+	user_data_dir = g_build_filename (g_get_user_data_dir (),
+	                                  "tracker",
+	                                  "data",
+	                                  NULL);
+
+	data_dir = g_build_filename (g_get_user_cache_dir (),
+	                             "tracker",
+	                             NULL);
+
+	for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
+		dir = location_to_directory (dbs[i].location);
+		dbs[i].abs_filename = g_build_filename (dir, dbs[i].file, NULL);
+
+		if (old_flags & TRACKER_DB_MANAGER_LOW_MEMORY_MODE) {
+			dbs[i].cache_size /= 2;
+		}
+	}
+
+	locations_initialized = TRUE;
+}
+
 gboolean
 tracker_db_manager_init (TrackerDBManagerFlags  flags,
                          gboolean              *first_time,
@@ -1067,7 +1103,7 @@ tracker_db_manager_init (TrackerDBManagerFlags  flags,
 	gchar              *filename;
 	const gchar        *dir;
 	const gchar        *env_path;
-	gboolean            need_reindex, did_copy = FALSE;
+	gboolean            need_reindex;
 	guint               i;
 	gchar              *in_use_filename;
 	int                 in_use_file;
@@ -1098,7 +1134,11 @@ tracker_db_manager_init (TrackerDBManagerFlags  flags,
 	/* Set up locations */
 	g_message ("Setting database locations");
 
+	old_flags = flags;
+
 	filename = g_strdup_printf ("tracker-%s", g_get_user_name ());
+	if (sys_tmp_dir)
+		g_free (sys_tmp_dir);
 	sys_tmp_dir = g_build_filename (g_get_tmp_dir (), filename, NULL);
 	g_free (filename);
 
@@ -1112,11 +1152,17 @@ tracker_db_manager_init (TrackerDBManagerFlags  flags,
 		sql_dir = g_strdup (env_path);
 	}
 
+	if (user_data_dir)
+		g_free (user_data_dir);
+
 	user_data_dir = g_build_filename (g_get_user_data_dir (),
 	                                  "tracker",
 	                                  "data",
 	                                  NULL);
 
+	if (data_dir)
+		g_free (data_dir);
+
 	data_dir = g_build_filename (g_get_user_cache_dir (),
 	                             "tracker",
 	                             NULL);
@@ -1146,6 +1192,8 @@ tracker_db_manager_init (TrackerDBManagerFlags  flags,
 	for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
 		/* Fill absolute path for the database */
 		dir = location_to_directory (dbs[i].location);
+		if (dbs[i].abs_filename)
+			g_free (dbs[i].abs_filename);
 		dbs[i].abs_filename = g_build_filename (dir, dbs[i].file, NULL);
 
 		if (flags & TRACKER_DB_MANAGER_LOW_MEMORY_MODE) {
@@ -1170,6 +1218,8 @@ tracker_db_manager_init (TrackerDBManagerFlags  flags,
 		}
 	}
 
+	locations_initialized = TRUE;
+
 	/* If we are just initializing to remove the databases,
 	 * return here.
 	 */
@@ -1316,60 +1366,10 @@ tracker_db_manager_init (TrackerDBManagerFlags  flags,
 		                                                        TRACKER_DB_CONTENTS);
 	}
 
-	if (did_copy) {
-		tracker_db_backup_sync_fts ();
-	}
-
 	return TRUE;
 }
 
 void
-tracker_db_manager_disconnect (void)
-{
-	if (resources_iface) {
-		guint i;
-		TrackerDB attachments[2] = { TRACKER_DB_FULLTEXT,
-		                             TRACKER_DB_CONTENTS };
-
-		for (i = 0; i < 2; i++) {
-			TrackerDB db = attachments [i];
-
-			db_exec_no_reply (resources_iface,
-			                  "DETACH '%s'",
-			                  dbs[db].name);
-		}
-
-		tracker_db_interface_disconnect (resources_iface);
-	}
-}
-
-void
-tracker_db_manager_reconnect (void)
-{
-	if (resources_iface) {
-		guint i;
-		TrackerDB attachments[2] = { TRACKER_DB_FULLTEXT,
-		                             TRACKER_DB_CONTENTS };
-
-		tracker_db_interface_reconnect (resources_iface);
-
-		db_set_params (resources_iface,
-		               dbs[TRACKER_DB_METADATA].cache_size,
-		               dbs[TRACKER_DB_METADATA].page_size,
-		               TRUE);
-
-		for (i = 0; i < 2; i++) {
-			TrackerDB db = attachments [i];
-
-			db_exec_no_reply (resources_iface,
-			                  "ATTACH '%s' as '%s'",
-			                  dbs[db].abs_filename,
-			                  dbs[db].name);
-		}
-	}
-}
-
-void
 tracker_db_manager_shutdown (void)
 {
 	guint i;
@@ -1392,8 +1392,11 @@ tracker_db_manager_shutdown (void)
 	}
 
 	g_free (data_dir);
+	data_dir = NULL;
 	g_free (user_data_dir);
+	user_data_dir = NULL;
 	g_free (sys_tmp_dir);
+	sys_tmp_dir = NULL;
 	g_free (sql_dir);
 
 	if (resources_iface) {
@@ -1418,6 +1421,7 @@ tracker_db_manager_shutdown (void)
 	tracker_ontology_shutdown ();
 
 	initialized = FALSE;
+	locations_initialized = FALSE;
 
 	in_use_filename = g_build_filename (g_get_user_data_dir (),
 	                                    "tracker",
@@ -1431,11 +1435,94 @@ tracker_db_manager_shutdown (void)
 }
 
 void
-tracker_db_manager_remove_all (gboolean rm_backup_and_log)
+tracker_db_manager_remove_all (gboolean rm_journal)
+{
+	g_return_if_fail (initialized != FALSE);
+
+	db_manager_remove_all (rm_journal);
+}
+
+
+void
+tracker_db_manager_move_to_temp (void)
 {
+	guint i;
+	gchar *cpath, *new_filename;
+
 	g_return_if_fail (initialized != FALSE);
 
-	db_manager_remove_all (rm_backup_and_log, FALSE);
+	g_message ("Moving all database files");
+
+	for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
+		new_filename = g_strdup_printf ("%s.tmp", dbs[i].abs_filename);
+		g_message ("  Renaming database:'%s' -> '%s'",
+		           dbs[i].abs_filename, new_filename);
+		g_rename (dbs[i].abs_filename, new_filename);
+		g_free (new_filename);
+	}
+
+	cpath = g_strdup (tracker_db_journal_get_filename ());
+	new_filename = g_strdup_printf ("%s.tmp", cpath);
+	g_message ("  Renaming journal:'%s' -> '%s'",
+	           cpath, new_filename);
+	g_rename (cpath, new_filename);
+	g_free (cpath);
+	g_free (new_filename);
+}
+
+
+void
+tracker_db_manager_restore_from_temp (void)
+{
+	guint i;
+	gchar *cpath, *new_filename;
+
+	g_return_if_fail (locations_initialized != FALSE);
+
+	g_message ("Moving all database files");
+
+	for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
+		new_filename = g_strdup_printf ("%s.tmp", dbs[i].abs_filename);
+		g_message ("  Renaming database:'%s' -> '%s'",
+		           dbs[i].abs_filename, new_filename);
+		g_rename (dbs[i].abs_filename, new_filename);
+		g_free (new_filename);
+	}
+
+	cpath = g_strdup (tracker_db_journal_get_filename ());
+	new_filename = g_strdup_printf ("%s.tmp", cpath);
+	g_message ("  Renaming journal:'%s' -> '%s'",
+	           cpath, new_filename);
+	g_rename (cpath, new_filename);
+	g_free (cpath);
+	g_free (new_filename);
+}
+
+void
+tracker_db_manager_remove_temp (void)
+{
+	guint i;
+	gchar *cpath, *new_filename;
+
+	g_return_if_fail (locations_initialized != FALSE);
+
+	g_message ("Removing all temp database files");
+
+	for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
+		new_filename = g_strdup_printf ("%s.tmp", dbs[i].abs_filename);
+		g_message ("  Removing temp database:'%s'",
+		           new_filename);
+		g_unlink (new_filename);
+		g_free (new_filename);
+	}
+
+	cpath = g_strdup (tracker_db_journal_get_filename ());
+	new_filename = g_strdup_printf ("%s.tmp", cpath);
+	g_message ("  Removing temp journal:'%s'",
+	           new_filename);
+	g_unlink (new_filename);
+	g_free (cpath);
+	g_free (new_filename);
 }
 
 void
diff --git a/src/libtracker-db/tracker-db-manager.h b/src/libtracker-db/tracker-db-manager.h
index f7c6636..5947652 100644
--- a/src/libtracker-db/tracker-db-manager.h
+++ b/src/libtracker-db/tracker-db-manager.h
@@ -47,17 +47,22 @@ typedef enum {
 	TRACKER_DB_MANAGER_READONLY         = 1 << 5
 } TrackerDBManagerFlags;
 
-GType               tracker_db_get_type                         (void) G_GNUC_CONST;
-gboolean            tracker_db_manager_init             (TrackerDBManagerFlags  flags,
-                                                         gboolean              *first_time,
-                                                         gboolean               shared_cache);
-void                tracker_db_manager_shutdown         (void);
-void                tracker_db_manager_remove_all       (gboolean               rm_backup_and_log);
-void                tracker_db_manager_optimize         (void);
-const gchar *       tracker_db_manager_get_file         (TrackerDB              db);
-TrackerDBInterface *tracker_db_manager_get_db_interface (void);
-void                tracker_db_manager_disconnect       (void);
-void                tracker_db_manager_reconnect        (void);
+GType               tracker_db_get_type                  (void) G_GNUC_CONST;
+gboolean            tracker_db_manager_init              (TrackerDBManagerFlags  flags,
+                                                          gboolean              *first_time,
+                                                          gboolean               shared_cache);
+void                tracker_db_manager_shutdown          (void);
+void                tracker_db_manager_remove_all        (gboolean               rm_journal);
+void                tracker_db_manager_optimize          (void);
+const gchar *       tracker_db_manager_get_file          (TrackerDB              db);
+TrackerDBInterface *tracker_db_manager_get_db_interface  (void);
+void                tracker_db_manager_remove_temp       (void);
+void                tracker_db_manager_move_to_temp      (void);
+void                tracker_db_manager_restore_from_temp (void);
+void                tracker_db_manager_init_locations    (void);
+
+TrackerDBManagerFlags
+                    tracker_db_manager_get_flags         (void);
 
 G_END_DECLS
 
diff --git a/src/tracker-store/tracker-backup.c b/src/tracker-store/tracker-backup.c
index 478ccda..b931317 100644
--- a/src/tracker-store/tracker-backup.c
+++ b/src/tracker-store/tracker-backup.c
@@ -34,8 +34,6 @@
 typedef struct {
 	DBusGMethodInvocation *context;
 	guint request_id;
-	gboolean play_journal;
-	GFile *destination, *journal;
 } TrackerDBusMethodInfo;
 
 G_DEFINE_TYPE (TrackerBackup, tracker_backup, G_TYPE_OBJECT)
@@ -57,22 +55,6 @@ tracker_backup_new (void)
 }
 
 static void
-destroy_method_info (gpointer user_data)
-{
-	TrackerDBusMethodInfo *info = user_data;
-
-	if (info->destination) {
-		g_object_unref (info->destination);
-	}
-
-	if (info->journal) {
-		g_object_unref (info->journal);
-	}
-
-	g_free (info);
-}
-
-static void
 backup_callback (GError *error, gpointer user_data)
 {
 	TrackerDBusMethodInfo *info = user_data;
@@ -92,29 +74,15 @@ backup_callback (GError *error, gpointer user_data)
 	                              info->context);
 }
 
-static void
-on_batch_commit (gpointer user_data)
-{
-	TrackerDBusMethodInfo *info = user_data;
-
-	/* At this point no transactions are left open, we can now start the
-	 * sqlite3_backup API, which will run itself as a GSource within the
-	 * mainloop after it got initialized (which will reopen the mainloop) */
-
-	tracker_data_backup_save (info->destination, info->journal,
-	                          backup_callback,
-	                          info, destroy_method_info);
-}
-
 void
 tracker_backup_save (TrackerBackup          *object,
                      const gchar            *destination_uri,
-                     const gchar            *journal_uri,
                      DBusGMethodInvocation  *context,
                      GError                **error)
 {
 	guint request_id;
 	TrackerDBusMethodInfo *info;
+	GFile *destination;
 
 	request_id = tracker_dbus_get_next_request_id ();
 
@@ -127,57 +95,43 @@ tracker_backup_save (TrackerBackup          *object,
 
 	info->request_id = request_id;
 	info->context = context;
-	info->play_journal = FALSE;
-	info->destination = g_file_new_for_uri (destination_uri);
-	info->journal = g_file_new_for_uri (journal_uri);
+	destination = g_file_new_for_uri (destination_uri);
 
-	/* The sqlite3_backup API apparently doesn't much like open transactions,
-	 * this queue_commit will first call the currently open transaction
-	 * of the open batch (if any), and then in the callback we'll idd
-	 * continue with making the backup itself (using sqlite3_backup's API) */
+	tracker_data_backup_save (destination,
+	                          backup_callback,
+	                          info, 
+	                          (GDestroyNotify) g_free);
 
-	tracker_store_queue_commit (on_batch_commit, NULL, info, NULL);
+	g_object_unref (destination);
 }
 
 void
 tracker_backup_restore (TrackerBackup          *object,
-                        const gchar            *backup_uri,
                         const gchar            *journal_uri,
                         DBusGMethodInvocation  *context,
                         GError                **error)
 {
 	guint request_id;
 	TrackerDBusMethodInfo *info;
-	GFile *destination, *journal;
+	GFile *journal;
 
 	request_id = tracker_dbus_get_next_request_id ();
 
 	tracker_dbus_request_new (request_id,
 	                          context,
 	                          "D-Bus request to restore backup from '%s'",
-	                          backup_uri);
-
-	destination = g_file_new_for_uri (backup_uri);
-	journal = g_file_new_for_uri (journal_uri);
+	                          journal_uri);
 
 	info = g_new0 (TrackerDBusMethodInfo, 1);
-
 	info->request_id = request_id;
 	info->context = context;
-	info->play_journal = TRUE;
-
-	/* This call is mostly synchronous, because we want to block the
-	 * mainloop during a restore procedure (you're switching the active
-	 * database here, let's not allow queries during this time)
-	 *
-	 * No need for commits or anything. Whatever is in the current db will
-	 * be eliminated in favor of the data in `backup_uri` and `journal_uri`. */
+	journal = g_file_new_for_uri (journal_uri);
 
-	tracker_data_backup_restore (destination, journal,
+	tracker_data_backup_restore (journal,
 	                             backup_callback,
-	                             info, destroy_method_info);
+	                             info, 
+	                             (GDestroyNotify) g_free);
 
-	g_object_unref (destination);
 	g_object_unref (journal);
 }
 
diff --git a/src/tracker-store/tracker-backup.h b/src/tracker-store/tracker-backup.h
index 2eebc2f..d59c07f 100644
--- a/src/tracker-store/tracker-backup.h
+++ b/src/tracker-store/tracker-backup.h
@@ -52,11 +52,9 @@ GType          tracker_backup_get_type (void) G_GNUC_CONST;
 TrackerBackup *tracker_backup_new      (void);
 void           tracker_backup_save     (TrackerBackup          *object,
                                         const gchar            *destination_uri,
-                                        const gchar            *journal_uri,
                                         DBusGMethodInvocation  *context,
                                         GError                **error);
 void           tracker_backup_restore  (TrackerBackup          *object,
-                                        const gchar            *backup_uri,
                                         const gchar            *journal_uri,
                                         DBusGMethodInvocation  *context,
                                         GError                **error);



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