[tracker] tracker-writeback: Do proper error handling in the writeback program
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker-writeback: Do proper error handling in the writeback program
- Date: Tue, 20 Sep 2011 10:41:27 +0000 (UTC)
commit e728cf75cd4b1ddd071f2742950d01bd743d6bc7
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Sep 20 12:36:11 2011 +0200
tracker-writeback: Do proper error handling in the writeback program
The writeback_file_finished in the miner-fs requires that in case no rename()
happens at the end (which is the case in case the module's function returned
FALSE at the end of tracker_writeback_file_update_metadata), that an error is
returned for the DBus Method PerformWriteback.
I encountered a situation where xmp_files_open_new returned NULL in the module
function writeback_xmp_update_file_metadata of tracker-writeback-xmp.c, this
resulted in a FALSE return causing a unlink instead of rename of the temporary
file. This made miner-fs's handling for that fail.
src/tracker-writeback/tracker-writeback-file.c | 26 +++++++++++++-------
src/tracker-writeback/tracker-writeback-file.h | 13 +++++----
src/tracker-writeback/tracker-writeback-module.c | 12 +++++----
src/tracker-writeback/tracker-writeback-module.h | 26 ++++++++++---------
src/tracker-writeback/tracker-writeback-playlist.c | 6 +++-
src/tracker-writeback/tracker-writeback-taglib.c | 24 ++++++++++--------
src/tracker-writeback/tracker-writeback-xmp.c | 20 ++++++++++----
src/tracker-writeback/tracker-writeback.c | 18 ++++++++++++-
8 files changed, 92 insertions(+), 53 deletions(-)
---
diff --git a/src/tracker-writeback/tracker-writeback-file.c b/src/tracker-writeback/tracker-writeback-file.c
index 5092e18..829af11 100644
--- a/src/tracker-writeback/tracker-writeback-file.c
+++ b/src/tracker-writeback/tracker-writeback-file.c
@@ -28,10 +28,11 @@
#include "tracker-writeback-file.h"
-static gboolean tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerSparqlConnection *connection,
- GCancellable *cancellable);
+static gboolean tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error);
G_DEFINE_ABSTRACT_TYPE (TrackerWritebackFile, tracker_writeback_file, TRACKER_TYPE_WRITEBACK)
@@ -123,10 +124,11 @@ create_temporary_file (GFile *file,
}
static gboolean
-tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerSparqlConnection *connection,
- GCancellable *cancellable)
+tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error)
{
TrackerWritebackFileClass *writeback_file_class;
gboolean retval;
@@ -136,6 +138,7 @@ tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
const gchar * const *content_types;
const gchar *mime_type;
guint n;
+ GError *n_error = NULL;
writeback_file_class = TRACKER_WRITEBACK_FILE_GET_CLASS (writeback);
@@ -201,7 +204,8 @@ tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
tmp_file,
values,
connection,
- cancellable);
+ cancellable,
+ &n_error);
if (!retval) {
/* Delete the temporary file and preserve original */
@@ -216,5 +220,9 @@ tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
g_object_unref (tmp_file);
g_object_unref (file);
+ if (n_error) {
+ g_propagate_error (error, n_error);
+ }
+
return retval;
}
diff --git a/src/tracker-writeback/tracker-writeback-file.h b/src/tracker-writeback/tracker-writeback-file.h
index ca504a9..61fa865 100644
--- a/src/tracker-writeback/tracker-writeback-file.h
+++ b/src/tracker-writeback/tracker-writeback-file.h
@@ -43,12 +43,13 @@ struct TrackerWritebackFile {
struct TrackerWritebackFileClass {
TrackerWritebackClass parent_class;
- gboolean (* update_file_metadata) (TrackerWritebackFile *writeback_file,
- GFile *file,
- GPtrArray *values,
- TrackerSparqlConnection *connection,
- GCancellable *cancellable);
- const gchar * const * (* content_types) (TrackerWritebackFile *writeback_file);
+ gboolean (* update_file_metadata) (TrackerWritebackFile *writeback_file,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error);
+ const gchar * const * (* content_types) (TrackerWritebackFile *writeback_file);
};
diff --git a/src/tracker-writeback/tracker-writeback-module.c b/src/tracker-writeback/tracker-writeback-module.c
index 77026b1..f73ef7a 100644
--- a/src/tracker-writeback/tracker-writeback-module.c
+++ b/src/tracker-writeback/tracker-writeback-module.c
@@ -179,10 +179,11 @@ tracker_writeback_init (TrackerWriteback *writeback)
}
gboolean
-tracker_writeback_update_metadata (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerSparqlConnection *connection,
- GCancellable *cancellable)
+tracker_writeback_update_metadata (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error)
{
g_return_val_if_fail (TRACKER_IS_WRITEBACK (writeback), FALSE);
g_return_val_if_fail (values != NULL, FALSE);
@@ -191,7 +192,8 @@ tracker_writeback_update_metadata (TrackerWriteback *writeback,
return TRACKER_WRITEBACK_GET_CLASS (writeback)->update_metadata (writeback,
values,
connection,
- cancellable);
+ cancellable,
+ error);
}
return FALSE;
diff --git a/src/tracker-writeback/tracker-writeback-module.h b/src/tracker-writeback/tracker-writeback-module.h
index e9a4eb3..a9f6acf 100644
--- a/src/tracker-writeback/tracker-writeback-module.h
+++ b/src/tracker-writeback/tracker-writeback-module.h
@@ -50,10 +50,11 @@ struct TrackerWriteback {
struct TrackerWritebackClass {
GObjectClass parent_class;
- gboolean (* update_metadata) (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerSparqlConnection *connection,
- GCancellable *cancellable);
+ gboolean (* update_metadata) (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error);
};
struct TrackerWritebackModule {
@@ -72,21 +73,22 @@ struct TrackerWritebackModuleClass {
GType tracker_writeback_get_type (void) G_GNUC_CONST;
-gboolean tracker_writeback_update_metadata (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerSparqlConnection *connection,
- GCancellable *cancellable);
+gboolean tracker_writeback_update_metadata (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error);
TrackerMinerManager* tracker_writeback_get_miner_manager (void);
/* Entry functions to be defined by modules */
-TrackerWriteback * writeback_module_create (GTypeModule *module);
+TrackerWriteback * writeback_module_create (GTypeModule *module);
const gchar * const * writeback_module_get_rdf_types (void);
GType tracker_writeback_module_get_type (void) G_GNUC_CONST;
-TrackerWritebackModule *tracker_writeback_module_get (const gchar *name);
-TrackerWriteback * tracker_writeback_module_create (TrackerWritebackModule *module);
-const gchar * const * tracker_writeback_module_get_rdf_types (TrackerWritebackModule *module);
+TrackerWritebackModule *tracker_writeback_module_get (const gchar *name);
+TrackerWriteback * tracker_writeback_module_create (TrackerWritebackModule *module);
+const gchar * const * tracker_writeback_module_get_rdf_types (TrackerWritebackModule *module);
GList * tracker_writeback_modules_list (void);
G_END_DECLS
diff --git a/src/tracker-writeback/tracker-writeback-playlist.c b/src/tracker-writeback/tracker-writeback-playlist.c
index ca6f25f..64958a3 100644
--- a/src/tracker-writeback/tracker-writeback-playlist.c
+++ b/src/tracker-writeback/tracker-writeback-playlist.c
@@ -53,7 +53,8 @@ static gboolean writeback_playlist_update_file_metadata (TrackerWrit
GFile *file,
GPtrArray *values,
TrackerSparqlConnection *connection,
- GCancellable *cancellable);
+ GCancellable *cancellable,
+ GError **error);
static const gchar * const *writeback_playlist_content_types (TrackerWritebackFile *wbf);
G_DEFINE_DYNAMIC_TYPE (TrackerWritebackPlaylist, tracker_writeback_playlist, TRACKER_TYPE_WRITEBACK_FILE);
@@ -208,7 +209,8 @@ writeback_playlist_update_file_metadata (TrackerWritebackFile *writeback_fil
GFile *file,
GPtrArray *values,
TrackerSparqlConnection *connection,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GError **error)
{
guint n;
diff --git a/src/tracker-writeback/tracker-writeback-taglib.c b/src/tracker-writeback/tracker-writeback-taglib.c
index ca4f5de..40e290e 100644
--- a/src/tracker-writeback/tracker-writeback-taglib.c
+++ b/src/tracker-writeback/tracker-writeback-taglib.c
@@ -44,16 +44,17 @@ struct TrackerWritebackTaglibClass {
};
static GType tracker_writeback_taglib_get_type (void) G_GNUC_CONST;
-static gboolean writeback_taglib_update_file_metadata (TrackerWritebackFile *wbf,
- GFile *file,
- GPtrArray *values,
- TrackerSparqlConnection *connection,
- GCancellable *cancellable);
-static const gchar * const *writeback_taglib_content_types (TrackerWritebackFile *wbf);
-static gchar* writeback_taglib_get_artist_name (TrackerSparqlConnection *connection,
- const gchar *urn);
-static gchar* writeback_taglib_get_album_name (TrackerSparqlConnection *connection,
- const gchar *urn);
+static gboolean writeback_taglib_update_file_metadata (TrackerWritebackFile *wbf,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error);
+static const gchar * const *writeback_taglib_content_types (TrackerWritebackFile *wbf);
+static gchar* writeback_taglib_get_artist_name (TrackerSparqlConnection *connection,
+ const gchar *urn);
+static gchar* writeback_taglib_get_album_name (TrackerSparqlConnection *connection,
+ const gchar *urn);
G_DEFINE_DYNAMIC_TYPE (TrackerWritebackTaglib, tracker_writeback_taglib, TRACKER_TYPE_WRITEBACK_FILE);
@@ -136,7 +137,8 @@ writeback_taglib_update_file_metadata (TrackerWritebackFile *writeback_file,
GFile *file,
GPtrArray *values,
TrackerSparqlConnection *connection,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GError **error)
{
gboolean ret;
gchar *path;
diff --git a/src/tracker-writeback/tracker-writeback-xmp.c b/src/tracker-writeback/tracker-writeback-xmp.c
index d6a67d6..c3e3ed8 100644
--- a/src/tracker-writeback/tracker-writeback-xmp.c
+++ b/src/tracker-writeback/tracker-writeback-xmp.c
@@ -53,7 +53,8 @@ static gboolean writeback_xmp_update_file_metadata (TrackerWriteback
GFile *file,
GPtrArray *values,
TrackerSparqlConnection *connection,
- GCancellable *cancellable);
+ GCancellable *cancellable,
+ GError **error);
static const gchar * const *writeback_xmp_content_types (TrackerWritebackFile *writeback_file);
G_DEFINE_DYNAMIC_TYPE (TrackerWritebackXMP, tracker_writeback_xmp, TRACKER_TYPE_WRITEBACK_FILE);
@@ -106,11 +107,12 @@ writeback_xmp_content_types (TrackerWritebackFile *wbf)
}
static gboolean
-writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
- GFile *file,
- GPtrArray *values,
- TrackerSparqlConnection *connection,
- GCancellable *cancellable)
+writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error)
{
gchar *path;
guint n;
@@ -127,6 +129,12 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
xmp_files = xmp_files_open_new (path, XMP_OPEN_FORUPDATE);
if (!xmp_files) {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ "Can't open '%s' for update with Exempi (Exempi error code = %d)",
+ path,
+ xmp_get_error ());
g_free (path);
return FALSE;
}
diff --git a/src/tracker-writeback/tracker-writeback.c b/src/tracker-writeback/tracker-writeback.c
index b0e962d..5433ef4 100644
--- a/src/tracker-writeback/tracker-writeback.c
+++ b/src/tracker-writeback/tracker-writeback.c
@@ -46,6 +46,7 @@ typedef struct {
TrackerSparqlConnection *connection;
TrackerWriteback *writeback;
guint cancel_id;
+ GError *error;
} WritebackData;
typedef struct {
@@ -246,6 +247,7 @@ writeback_data_new (TrackerController *controller,
data->connection = g_object_ref (connection);
data->writeback = g_object_ref (writeback);
data->request = request;
+ data->error = NULL;
data->cancel_id = g_cancellable_connect (data->cancellable,
G_CALLBACK (task_cancellable_cancelled_cb),
@@ -266,6 +268,9 @@ writeback_data_free (WritebackData *data)
g_object_unref (data->writeback);
g_ptr_array_unref (data->results);
g_object_unref (data->cancellable);
+ if (data->error) {
+ g_error_free (data->error);
+ }
g_slice_free (WritebackData, data);
}
@@ -422,7 +427,13 @@ perform_writeback_cb (gpointer user_data)
data = user_data;
priv = data->controller->priv;
priv->ongoing_tasks = g_list_remove (priv->ongoing_tasks, data);
- g_dbus_method_invocation_return_value (data->invocation, NULL);
+
+ if (data->error == NULL) {
+ g_dbus_method_invocation_return_value (data->invocation, NULL);
+ } else {
+ g_dbus_method_invocation_return_gerror (data->invocation, data->error);
+ }
+
tracker_dbus_request_end (data->request, NULL);
g_mutex_lock (priv->mutex);
@@ -465,10 +476,13 @@ io_writeback_job (GIOSchedulerJob *job,
priv->current = data;
g_mutex_unlock (priv->mutex);
+ g_clear_error (&data->error);
+
tracker_writeback_update_metadata (data->writeback,
data->results,
data->connection,
- data->cancellable);
+ data->cancellable,
+ &data->error);
g_idle_add (perform_writeback_cb, data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]