From 5a7db3015ab0f14e4e2ad6766b3ce819447faf93 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 27 Nov 2013 17:43:18 -0800 Subject: [PATCH] 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 file changed, 7 insertions(+) diff --git a/gio/gfile.c b/gio/gfile.c index 3e2607c8d..4e25d38ca 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)