From 8dd9aeb11e25abb2ab82bfdd9bbda241a4e46172 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Thu, 22 May 2025 16:06:51 +0200 Subject: [PATCH] Cycles: Fix occasional failure in path_create_directories This PR adds a global mutex to `path_create_directories` to fix a thread-safety issue which can occur when concurrently creating multiple subdirectories with common stems. Pull Request: https://projects.blender.org/blender/blender/pulls/139266 --- intern/cycles/util/path.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/intern/cycles/util/path.cpp b/intern/cycles/util/path.cpp index 33cf0a39e33..307a013563b 100644 --- a/intern/cycles/util/path.cpp +++ b/intern/cycles/util/path.cpp @@ -620,13 +620,9 @@ string path_files_md5_hash(const string &dir) static bool create_directories_recursivey(const string &path) { - if (path_is_directory(path)) { - /* Directory already exists, nothing to do. */ - return true; - } if (path_exists(path)) { - /* File exists and it's not a directory. */ - return false; + /* Either directory exists and there is nothing to do, or it's a file and we fail. */ + return path_is_directory(path); } const string parent = path_dirname(path); @@ -638,10 +634,14 @@ static bool create_directories_recursivey(const string &path) #ifdef _WIN32 wstring path_wc = string_to_wstring(path); - return _wmkdir(path_wc.c_str()) == 0; + _wmkdir(path_wc.c_str()); #else - return mkdir(path.c_str(), 0777) == 0; + mkdir(path.c_str(), 0777); #endif + + /* If another thread creates this in the meantime mkdir will return an error, + * so instead check if the directory exists. */ + return path_is_directory(path); } void path_create_directories(const string &filepath)