[glib] gfile: make_directory_with_parents race condition



commit 5a7db3015ab0f14e4e2ad6766b3ce819447faf93
Author: Philip Chimento <philip chimento gmail com>
Date:   Wed Nov 27 17:43:18 2013 -0800

    gfile: make_directory_with_parents race condition
    
    A race condition could cause g_file_make_directory_with_parents() to
    fail with G_IO_ERROR_EXISTS despite the requested directory not
    existing.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=719455

 gio/gfile.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/gio/gfile.c b/gio/gfile.c
index 3e2607c..4e25d38 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -3777,6 +3777,11 @@ g_file_make_directory_with_parents (GFile         *file,
 
       g_clear_error (&my_error);
       g_file_make_directory (parent_file, cancellable, &my_error);
+      /* Another process may have created the directory in between the
+       * G_IO_ERROR_NOT_FOUND and now
+       */
+      if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+        g_clear_error (&my_error);
 
       g_object_unref (work_file);
       work_file = g_object_ref (parent_file);
@@ -3790,6 +3795,8 @@ g_file_make_directory_with_parents (GFile         *file,
   for (l = list; my_error == NULL && l; l = l->next)
     {
       g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
+      if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+        g_clear_error (&my_error);
     }
 
   if (work_file)


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