[gnome-photos] glib: Limit the scope of the GError
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] glib: Limit the scope of the GError
- Date: Thu, 7 Dec 2017 10:34:58 +0000 (UTC)
commit f259755ed22ca185906d6d837474e8e4d011652b
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Dec 5 12:19:38 2017 +0100
glib: Limit the scope of the GError
Even though it's not strictly necessary here, it's a good style to
follow. It reduces the chances of re-using the same GError without
ensuring that it is empty, and emphasizes that g_task_return_error
assumes ownership of the GError.
src/photos-glib.c | 69 +++++++++++++++++++++++++++-------------------------
1 files changed, 36 insertions(+), 33 deletions(-)
---
diff --git a/src/photos-glib.c b/src/photos-glib.c
index aa4fada..24dcd39 100644
--- a/src/photos-glib.c
+++ b/src/photos-glib.c
@@ -143,7 +143,6 @@ static void
photos_glib_file_create_create (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
GCancellable *cancellable;
- GError *error = NULL;
GFile *file = G_FILE (source_object);
g_autoptr (GFileOutputStream) stream = NULL;
g_autoptr (GTask) task = G_TASK (user_data);
@@ -152,38 +151,42 @@ photos_glib_file_create_create (GObject *source_object, GAsyncResult *res, gpoin
cancellable = g_task_get_cancellable (task);
data = (PhotosGLibFileCreateData *) g_task_get_task_data (task);
- stream = g_file_create_finish (file, res, &error);
- if (error != NULL)
- {
- g_autoptr (GFile) unique_file = NULL;
- g_autofree gchar *filename = NULL;
-
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
- {
- g_task_return_error (task, error);
- goto out;
- }
-
- if (data->count == G_MAXUINT)
- {
- g_task_return_new_error (task, PHOTOS_ERROR, 0, "Exceeded number of copies of a file");
- goto out;
- }
-
- data->count++;
-
- filename = photos_glib_file_create_data_get_filename (data);
- unique_file = g_file_get_child (data->dir, filename);
-
- g_file_create_async (unique_file,
- data->flags,
- data->io_priority,
- cancellable,
- photos_glib_file_create_create,
- g_object_ref (task));
-
- goto out;
- }
+ {
+ g_autoptr (GError) error = NULL;
+
+ stream = g_file_create_finish (file, res, &error);
+ if (error != NULL)
+ {
+ g_autoptr (GFile) unique_file = NULL;
+ g_autofree gchar *filename = NULL;
+
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+ {
+ g_task_return_error (task, g_steal_pointer (&error));
+ goto out;
+ }
+
+ if (data->count == G_MAXUINT)
+ {
+ g_task_return_new_error (task, PHOTOS_ERROR, 0, "Exceeded number of copies of a file");
+ goto out;
+ }
+
+ data->count++;
+
+ filename = photos_glib_file_create_data_get_filename (data);
+ unique_file = g_file_get_child (data->dir, filename);
+
+ g_file_create_async (unique_file,
+ data->flags,
+ data->io_priority,
+ cancellable,
+ photos_glib_file_create_create,
+ g_object_ref (task));
+
+ goto out;
+ }
+ }
g_task_return_pointer (task, g_object_ref (stream), g_object_unref);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]