[tracker/gdbus-porting] libtracker-common, miner-fs: Fix error handling of FD passing support



commit 97b666b4f0fece0e662506c67ebe81d974c27b20
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Jan 6 12:40:04 2011 +0100

    libtracker-common, miner-fs: Fix error handling of FD passing support

 src/libtracker-common/tracker-dbus.c |   65 ++++++++++-----------------------
 src/libtracker-common/tracker-dbus.h |    3 +-
 src/miners/fs/tracker-miner-files.c  |    9 +----
 3 files changed, 22 insertions(+), 55 deletions(-)
---
diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index 6ee35f2..be5359a 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -531,55 +531,36 @@ tracker_dbus_send_and_splice_async_finish (GObject      *source,
 
 	if (!error) {
 		if (g_dbus_message_get_message_type (data->reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
+			gchar *print;
+
+			print = g_dbus_message_print (data->reply, 0);
+			g_set_error (&error,
+			             TRACKER_DBUS_ERROR,
+			             TRACKER_DBUS_ERROR_UNSUPPORTED,
+			             "%s", print);
+			g_free (print);
 
-			/* If any error happened, we're not passing any received data, so we
-			 * need to free it */
 			g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)));
 
-			(* data->callback) (NULL, -1, NULL, error, data->user_data);
+			(* data->callback) (NULL, -1, error, data->user_data);
 
-			/* Note: GError should be freed by callback. We do this to be aligned
-			 * with the behavior of dbus-glib, where if an error happens, the
-			 * GError passed to the callback is supposed to be disposed by the
-			 * callback itself. */
+			g_error_free (error);
 		} else {
-			GStrv v_names = NULL;
-
 			(* data->callback) (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
 			                    g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
-			                    v_names,
 			                    NULL,
 			                    data->user_data);
 
-			/* Don't use g_strfreev here, see above */
-			g_free (v_names);
 		}
 	} else {
-		/* If any error happened, we're not passing any received data, so we
-		 * need to free it */
 		g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)));
-
-		(* data->callback) (NULL, -1, NULL, error, data->user_data);
-
-		/* Note: GError should be freed by callback. We do this to be aligned
-		 * with the behavior of dbus-glib, where if an error happens, the
-		 * GError passed to the callback is supposed to be disposed by the
-		 * callback itself. */
+		(* data->callback) (NULL, -1, error, data->user_data);
+		g_error_free (error);
 	}
 
 	send_and_splice_data_free (data);
 }
 
-static void
-tracker_g_async_ready_callback (GObject      *source_object,
-                                GAsyncResult *res,
-                                gpointer      user_data)
-{
-	g_simple_async_result_set_op_res_gpointer (user_data, g_object_ref (res), g_object_unref);
-	g_simple_async_result_complete (user_data);
-	g_object_unref (user_data);
-}
-
 gboolean
 tracker_dbus_send_and_splice_async (GDBusConnection                  *connection,
                                     GDBusMessage                     *message,
@@ -592,7 +573,6 @@ tracker_dbus_send_and_splice_async (GDBusConnection                  *connection
 	GInputStream *unix_input_stream;
 	GInputStream *buffered_input_stream;
 	GOutputStream *output_stream;
-	GSimpleAsyncResult *result;
 
 	g_return_val_if_fail (connection != NULL, FALSE);
 	g_return_val_if_fail (message != NULL, FALSE);
@@ -604,10 +584,12 @@ tracker_dbus_send_and_splice_async (GDBusConnection                  *connection
 	                                                           TRACKER_DBUS_PIPE_BUFFER_SIZE);
 	output_stream = g_memory_output_stream_new (NULL, 0, g_realloc, NULL);
 
-	result = g_simple_async_result_new (G_OBJECT (connection),
-	                                    tracker_dbus_send_and_splice_async_finish,
-	                                    user_data,
-	                                    g_dbus_connection_send_message_with_reply);
+	data = send_and_splice_data_new (unix_input_stream,
+	                                 buffered_input_stream,
+	                                 output_stream,
+	                                 cancellable,
+	                                 callback,
+	                                 user_data);
 
 	g_dbus_connection_send_message_with_reply (connection,
 	                                           message,
@@ -615,15 +597,8 @@ tracker_dbus_send_and_splice_async (GDBusConnection                  *connection
 	                                           -1,
 	                                           NULL,
 	                                           cancellable,
-	                                           tracker_g_async_ready_callback,
-	                                           result);
-
-	data = send_and_splice_data_new (unix_input_stream,
-	                                 buffered_input_stream,
-	                                 output_stream,
-	                                 cancellable,
-	                                 callback,
-	                                 user_data);
+	                                           tracker_dbus_send_and_splice_async_finish,
+	                                           data);
 
 	g_output_stream_splice_async (data->output_stream,
 	                              data->buffered_input_stream,
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index 6d41910..1391daf 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -119,8 +119,7 @@ G_BEGIN_DECLS
 
 typedef void (*TrackerDBusSendAndSpliceCallback) (void     *buffer,
                                                   gssize    buffer_size,
-                                                  GStrv     variable_names,
-                                                  GError   *error,
+                                                  GError   *error, /* Don't free */
                                                   gpointer  user_data);
 
 typedef struct _TrackerDBusRequest TrackerDBusRequest;
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 05cb35a..88bc474 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -1854,9 +1854,6 @@ extractor_get_embedded_metadata_cb (gchar    *preupdate,
 		/* Something bad happened, notify about the error */
 		tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, error);
 		process_file_data_free (data);
-		/* Always free input GError. We want to behave exactly as if this
-		 * callback were one used in an async dbus-glib query.  */
-		g_error_free (error);
 		return;
 	}
 
@@ -1951,6 +1948,7 @@ fast_async_data_new (fast_async_cb  callback,
 	FastAsyncData *data;
 
 	data = g_slice_new0 (FastAsyncData);
+
 	data->callback = callback;
 	data->user_data = user_data;
 
@@ -1966,7 +1964,6 @@ fast_async_data_free (FastAsyncData *data)
 static void
 get_metadata_fast_cb (void     *buffer,
                       gssize    buffer_size,
-                      GStrv     variable_names,
                       GError   *error,
                       gpointer  user_data)
 {
@@ -1981,11 +1978,7 @@ get_metadata_fast_cb (void     *buffer,
 	preupdate = buffer;
 	if (G_UNLIKELY (error)) {
 		if (error->code != G_IO_ERROR_CANCELLED) {
-			/* ProcessFileData and error are freed in the callback */
 			(* data->callback) (NULL, NULL, error, process_data);
-		} else {
-			/* Free error ourselves */
-			g_error_free (error);
 		}
 	} else {
 		if (buffer_size) {



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