g_file_make_directory_with_parents: clean up logic
authorOwen W. Taylor <otaylor@fishsoup.net>
Tue, 14 Aug 2012 15:25:56 +0000 (11:25 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 16 Aug 2012 22:08:06 +0000 (18:08 -0400)
Simplify logic by only looking at whether we have a GError and
not also using return codes.

https://bugzilla.gnome.org/show_bug.cgi?id=680823

gio/gfile.c

index 92776af..5c43e57 100644 (file)
@@ -3360,7 +3360,6 @@ g_file_make_directory_with_parents (GFile         *file,
                                    GCancellable  *cancellable,
                                    GError       **error)
 {
-  gboolean result;
   GFile *work_file = NULL;
   GList *list = NULL, *l;
   GError *my_error = NULL;
@@ -3370,17 +3369,17 @@ g_file_make_directory_with_parents (GFile         *file,
   if (g_cancellable_set_error_if_cancelled (cancellable, error))
     return FALSE;
   
-  result = g_file_make_directory (file, cancellable, &my_error);
-  if (result || my_error->code != G_IO_ERROR_NOT_FOUND) 
+  g_file_make_directory (file, cancellable, &my_error);
+  if (my_error == NULL || my_error->code != G_IO_ERROR_NOT_FOUND)
     {
       if (my_error)
         g_propagate_error (error, my_error);
-      return result;
+      return my_error == NULL;
     }
   
   work_file = g_object_ref (file);
   
-  while (!result && my_error->code == G_IO_ERROR_NOT_FOUND) 
+  while (my_error != NULL && my_error->code == G_IO_ERROR_NOT_FOUND)
     {
       GFile *parent_file;
 
@@ -3389,21 +3388,20 @@ g_file_make_directory_with_parents (GFile         *file,
         break;
 
       g_clear_error (&my_error);
-
-      result = g_file_make_directory (parent_file, cancellable, &my_error);
+      g_file_make_directory (parent_file, cancellable, &my_error);
 
       g_object_unref (work_file);
       work_file = g_object_ref (parent_file);
 
-      if (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
+      if (my_error != NULL && my_error->code == G_IO_ERROR_NOT_FOUND)
         list = g_list_prepend (list, parent_file);  /* Transfer ownership of ref */
       else
         g_object_unref (parent_file);
     }
 
-  for (l = list; result && l; l = l->next)
+  for (l = list; my_error == NULL && l; l = l->next)
     {
-      result = g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
+      g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
     }
 
   if (work_file)
@@ -3416,10 +3414,10 @@ g_file_make_directory_with_parents (GFile         *file,
       list = g_list_remove (list, list->data);
     }
 
-  if (!result) 
+  if (my_error != NULL)
     {
       g_propagate_error (error, my_error);
-      return result;
+      return FALSE;
     }
   
   return g_file_make_directory (file, cancellable, error);