[glib/glib-2-42] gfile: make_directory_with_parents race condition



commit 70784ad1b71078b8ad7e947d71193320b60888b9
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 61ddaac..b40e46a 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -3771,6 +3771,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);
@@ -3784,6 +3789,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]