[tracker/gdbus: 8/101] libtracker-data: Do not use callback for tracker_data_backup_restore



commit fed1b22d987fbbd1b70c684f07d0263b33872fd1
Author: Jürg Billeter <j bitron ch>
Date:   Fri Jan 14 13:23:32 2011 +0100

    libtracker-data: Do not use callback for tracker_data_backup_restore
    
    It is a synchronous function, the callback does not serve any purpose.

 src/libtracker-data/libtracker-data.vapi    |    4 +-
 src/libtracker-data/tracker-data-backup.c   |   34 ++++++------------
 src/libtracker-data/tracker-data-backup.h   |    6 +--
 src/tracker-store/tracker-backup.c          |   52 ++++++++++++---------------
 tests/libtracker-data/tracker-backup-test.c |    5 ++-
 5 files changed, 41 insertions(+), 60 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index d5bba5a..8d0a7e8 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2010, Nokia
+ * Copyright (C) 2008-2011, Nokia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -196,7 +196,7 @@ namespace Tracker {
 		public delegate void BackupFinished (GLib.Error error);
 
 		public void backup_save (GLib.File destination, owned BackupFinished callback);
-		public void backup_restore (GLib.File journal, owned BackupFinished callback, [CCode (array_length = false)] string[]? test_schema, BusyCallback busy_callback);
+		public void backup_restore (GLib.File journal, [CCode (array_length = false)] string[]? test_schema, BusyCallback busy_callback) throws GLib.Error;
 	}
 
 	[CCode (cheader_filename = "libtracker-data/tracker-data-manager.h")]
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index d86be0d..fbc78d1 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -314,35 +314,18 @@ tracker_data_backup_save (GFile *destination,
 	g_strfreev (argv);
 }
 
-static gboolean
-on_restore_done (BackupSaveInfo *info)
-{
-	if (info->callback) {
-		info->callback (info->error, info->user_data);
-	}
-
-	free_backup_save_info (info);
-
-	return FALSE;
-}
-
 void
-tracker_data_backup_restore (GFile *journal,
-                             TrackerDataBackupFinished callback,
-                             gpointer user_data,
-                             GDestroyNotify destroy,
-                             const gchar **test_schemas,
-                             TrackerBusyCallback busy_callback,
-                             gpointer busy_user_data)
+tracker_data_backup_restore (GFile                *journal,
+                             const gchar         **test_schemas,
+                             TrackerBusyCallback   busy_callback,
+                             gpointer              busy_user_data,
+                             GError              **error)
 {
 	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;
@@ -414,6 +397,11 @@ tracker_data_backup_restore (GFile *journal,
 		             "Backup file doesn't exist");
 	}
 
-	on_restore_done (info);
+	if (info->error) {
+		g_propagate_error (error, info->error);
+		info->error = NULL;
+	}
+
+	free_backup_save_info (info);
 }
 
diff --git a/src/libtracker-data/tracker-data-backup.h b/src/libtracker-data/tracker-data-backup.h
index 5811d38..072cdc5 100644
--- a/src/libtracker-data/tracker-data-backup.h
+++ b/src/libtracker-data/tracker-data-backup.h
@@ -43,12 +43,10 @@ void   tracker_data_backup_save        (GFile                     *destination,
                                         gpointer                   user_data,
                                         GDestroyNotify             destroy);
 void   tracker_data_backup_restore     (GFile                     *journal,
-                                        TrackerDataBackupFinished  callback,
-                                        gpointer                   user_data,
-                                        GDestroyNotify             destroy,
                                         const gchar              **test_schema,
                                         TrackerBusyCallback        busy_callback,
-                                        gpointer                   busy_user_data);
+                                        gpointer                   busy_user_data,
+                                        GError                   **error);
 
 G_END_DECLS
 
diff --git a/src/tracker-store/tracker-backup.c b/src/tracker-store/tracker-backup.c
index d597c57..6b2ee61 100644
--- a/src/tracker-store/tracker-backup.c
+++ b/src/tracker-store/tracker-backup.c
@@ -85,31 +85,6 @@ backup_callback (GError *error, gpointer user_data)
 }
 
 static void
-restore_callback (GError *error, gpointer user_data)
-{
-	TrackerDBusMethodInfo *info = user_data;
-
-	if (info->resources) {
-		tracker_events_init (info->getter);
-		tracker_resources_enable_signals (info->resources);
-		g_object_unref (info->resources);
-	}
-
-	if (error) {
-		tracker_dbus_request_end (info->request, error);
-		dbus_g_method_return_error (info->context, error);
-		return;
-	}
-
-	tracker_dbus_request_end (info->request, NULL);
-
-	dbus_g_method_return (info->context);
-
-	tracker_store_set_active (TRUE, NULL, NULL);
-}
-
-
-static void
 backup_idle_set_active_false_cb (gpointer user_data)
 {
 	TrackerDBusMethodInfo *info = user_data;
@@ -162,6 +137,7 @@ restore_idle_set_active_false_cb (gpointer user_data)
 	TrackerStatus *notifier;
 	TrackerBusyCallback busy_callback;
 	gpointer busy_user_data;
+	GError *error = NULL;
 
 	journal = g_file_new_for_uri (info->journal_uri);
 
@@ -173,12 +149,30 @@ restore_idle_set_active_false_cb (gpointer user_data)
 	g_free (info->journal_uri);
 
 	tracker_data_backup_restore (journal,
-	                             restore_callback,
-	                             info, 
-	                             (GDestroyNotify) g_free,
 	                             NULL,
 	                             busy_callback,
-	                             busy_user_data);
+	                             busy_user_data,
+	                             &error);
+
+	if (info->resources) {
+		tracker_events_init (info->getter);
+		tracker_resources_enable_signals (info->resources);
+		g_object_unref (info->resources);
+	}
+
+	if (error) {
+		tracker_dbus_request_end (info->request, error);
+		dbus_g_method_return_error (info->context, error);
+		return;
+	}
+
+	tracker_dbus_request_end (info->request, NULL);
+
+	dbus_g_method_return (info->context);
+
+	tracker_store_set_active (TRUE, NULL, NULL);
+
+	g_free (info);
 
 	g_object_unref (journal);
 }
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
index c1efba0..b5d7792 100644
--- a/tests/libtracker-data/tracker-backup-test.c
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -168,7 +168,8 @@ test_backup_and_restore_helper (gboolean journal)
 	                           NULL, FALSE, 100, 100, NULL, NULL, NULL);
 	check_content_in_db (0, 0);
 
-	tracker_data_backup_restore (backup_file, backup_finished_cb, NULL, NULL, (const gchar **) test_schemas, NULL, NULL);
+	tracker_data_backup_restore (backup_file, (const gchar **) test_schemas, NULL, NULL, &error);
+	g_assert_no_error (error);
 	check_content_in_db (3, 1);
 
 	g_free (test_schemas[0]);
@@ -176,7 +177,7 @@ test_backup_and_restore_helper (gboolean journal)
 	g_free (test_schemas[2]);
 	g_free (test_schemas[3]);
 
-	g_assert_cmpint (backup_calls, ==, 2);
+	g_assert_cmpint (backup_calls, ==, 1);
 
 	tracker_data_manager_shutdown ();
 }



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