[tracker/parser] Added restore-from-turtle backup support
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/parser] Added restore-from-turtle backup support
- Date: Wed, 19 Aug 2009 08:43:31 +0000 (UTC)
commit 517a81a9fe6cfa91083eba209ff24996c18db327
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Aug 19 10:41:58 2009 +0200
Added restore-from-turtle backup support
src/libtracker-data/tracker-data-backup.c | 67 +++++++++++++-------
src/libtracker-data/tracker-data-backup.h | 19 ++++--
src/tracker-store/tracker-backup.c | 99 ++++++++++-------------------
3 files changed, 89 insertions(+), 96 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index 124d53a..9a548ae 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -27,40 +27,59 @@
#include "tracker-data-backup.h"
-gboolean
-tracker_data_backup_save (GFile *turtle_file,
- GError **error)
+typedef struct {
+ TrackerBackupFinished callback;
+ gpointer user_data;
+ GDestroyNotify destroy;
+} UnImplementedInfo;
+
+GQuark
+tracker_data_backup_error_quark (void)
{
-#if 0
- TrackerDBResultSet *data;
- TrackerClass *service;
- TurtleFile *turtle_file;
-
- /* TODO: temporary location */
- if (g_file_test (turtle_filename, G_FILE_TEST_EXISTS)) {
- g_unlink (turtle_filename);
- }
+ return g_quark_from_static_string ("tracker-data-backup-error-quark");
+}
- turtle_file = tracker_turtle_open (turtle_filename);
+static gboolean
+unimplemented (gpointer user_data)
+{
+ UnImplementedInfo *info = user_data;
- g_message ("Saving metadata backup in turtle file");
+ g_warning ("tracker_data_backup_save is unimplemented");
- /* TODO */
+ if (info->callback) {
+ GError *error = NULL;
- service = tracker_ontology_get_service_by_name ("Files");
- data = tracker_data_query_backup_metadata (service);
+ g_set_error (&error,
+ TRACKER_DB_BACKUP_ERROR,
+ TRACKER_DB_BACKUP_ERROR_UNKNOWN,
+ "tracker_data_backup_save is unimplemented");
- if (data) {
- extended_result_set_to_turtle (data, turtle_file);
- g_object_unref (data);
+ info->callback (error, info->user_data);
+ g_clear_error (&error);
}
- tracker_turtle_close (turtle_file);
+ if (info->destroy) {
+ info->destroy (info->user_data);
+ }
-#endif
+}
- g_warning ("tracker_data_backup_save is unimplemented");
+void
+tracker_data_backup_save (GFile *turtle_file,
+ TrackerBackupFinished callback,
+ gpointer user_data,
+ GDestroyNotify destroy)
+{
+ UnImplementedInfo *info = g_new(UnImplementedInfo, 1);
- return TRUE;
+ info->callback = callback;
+ info->user_data = user_data;
+ info->destroy = destroy;
+
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ callback,
+ info,
+ NULL);
}
+
diff --git a/src/libtracker-data/tracker-data-backup.h b/src/libtracker-data/tracker-data-backup.h
index 5a111e0..e0dc7ad 100644
--- a/src/libtracker-data/tracker-data-backup.h
+++ b/src/libtracker-data/tracker-data-backup.h
@@ -26,13 +26,20 @@
G_BEGIN_DECLS
-typedef void (* TrackerDataBackupRestoreFunc) (const gchar *subject,
- const gchar *predicate,
- const gchar *object,
- gpointer user_data);
+#define TRACKER_DB_BACKUP_ERROR (tracker_data_backup_error_quark ())
-gboolean tracker_data_backup_save (GFile *turtle_file,
- GError **error);
+typedef enum {
+ TRACKER_DB_BACKUP_ERROR_UNKNOWN,
+} TrackerDBBackupError;
+
+typedef void (*TrackerBackupFinished) (GError *error, gpointer user_data);
+
+GQuark tracker_data_backup_error_quark (void);
+
+void tracker_data_backup_save (GFile *turtle_file,
+ TrackerBackupFinished callback,
+ gpointer user_data,
+ GDestroyNotify destroy);
G_END_DECLS
diff --git a/src/tracker-store/tracker-backup.c b/src/tracker-store/tracker-backup.c
index e92d60d..f2b7d36 100644
--- a/src/tracker-store/tracker-backup.c
+++ b/src/tracker-store/tracker-backup.c
@@ -55,6 +55,30 @@ tracker_backup_new (void)
return g_object_new (TRACKER_TYPE_BACKUP, NULL);
}
+static void
+destroy_method_info (gpointer user_data)
+{
+ g_slice_free (TrackerDBusMethodInfo, user_data);
+}
+
+static void
+backup_callback (GError *error, gpointer user_data)
+{
+ TrackerDBusMethodInfo *info = user_data;
+
+ if (error) {
+ tracker_dbus_request_failed (info->request_id,
+ &error,
+ NULL);
+ dbus_g_method_return_error (info->context, error);
+ return;
+ }
+
+ dbus_g_method_return (info->context);
+
+ tracker_dbus_request_success (info->request_id);
+}
+
void
tracker_backup_save (TrackerBackup *object,
const gchar *uri,
@@ -62,16 +86,14 @@ tracker_backup_save (TrackerBackup *object,
GError **error)
{
guint request_id;
- GError *err = NULL;
+ TrackerDBusMethodInfo *info;
GFile *file;
request_id = tracker_dbus_get_next_request_id ();
tracker_dbus_request_new (request_id,
- "DBus request to save backup into '%s'",
- uri);
-
- g_message ("Backing up metadata (unfinished, unsupported)");
+ "DBus request to save backup into '%s'",
+ uri);
/* Previous DBus API accepted paths. For this reason I decided to try
* to support both paths and uris. Perhaps we should just remove the
@@ -83,49 +105,15 @@ tracker_backup_save (TrackerBackup *object,
file = g_file_new_for_uri (uri);
}
- tracker_data_backup_save (file, &err);
-
- g_object_unref (file);
-
- if (err) {
- GError *actual_error = NULL;
-
- tracker_dbus_request_failed (request_id,
- &actual_error,
- err->message);
-
- dbus_g_method_return_error (context, actual_error);
-
- g_error_free (actual_error);
- g_error_free (err);
- } else {
- dbus_g_method_return (context);
- tracker_dbus_request_success (request_id);
- }
-}
-
-static void
-destroy_method_info (gpointer user_data)
-{
- g_slice_free (TrackerDBusMethodInfo, user_data);
-}
-
-static void
-backup_callback (GError *error, gpointer user_data)
-{
- TrackerDBusMethodInfo *info = user_data;
+ info = g_slice_new (TrackerDBusMethodInfo);
- if (error) {
- tracker_dbus_request_failed (info->request_id,
- &error,
- NULL);
- dbus_g_method_return_error (info->context, error);
- return;
- }
+ info->request_id = request_id;
+ info->context = context;
- dbus_g_method_return (info->context);
+ tracker_data_backup_save (file, backup_callback,
+ info, destroy_method_info);
- tracker_dbus_request_success (info->request_id);
+ g_object_unref (file);
}
void
@@ -134,9 +122,7 @@ tracker_backup_restore (TrackerBackup *object,
DBusGMethodInvocation *context,
GError **error)
{
-#if 0
guint request_id;
- GError *actual_error = NULL;
TrackerDBusMethodInfo *info;
GFile *file;
@@ -146,24 +132,6 @@ tracker_backup_restore (TrackerBackup *object,
"DBus request to restore backup from '%s'",
uri);
- /* First check we have disk space */
-#if 0
- /* FIXME: MJR */
- if (tracker_status_get_is_paused_for_space ()) {
- tracker_dbus_request_failed (request_id,
- &actual_error,
- "No disk space left to write to"
- " the databases");
- dbus_g_method_return_error (context, actual_error);
- g_error_free (actual_error);
- return;
- }
-#endif
-
- tracker_dbus_request_new (request_id,
- "DBus request to restore backup '%s'",
- uri);
-
/* Previous DBus API accepted paths. For this reason I decided to try
* to support both paths and uris. Perhaps we should just remove the
* support for paths here? */
@@ -183,5 +151,4 @@ tracker_backup_restore (TrackerBackup *object,
info, destroy_method_info);
g_object_unref (file);
-#endif
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]