[glib] g_file_make_directory_with_parents: clean up logic



commit f899358156a34d1b5258d1fcdeb289e7b2bbf233
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Aug 14 11:25:56 2012 -0400

    g_file_make_directory_with_parents: clean up logic
    
    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 |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/gio/gfile.c b/gio/gfile.c
index 92776af..5c43e57 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -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);



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