From 4dd3e3562fb53adf580018814c5405eb7c2fb942 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 28 Apr 2014 14:57:05 +0000 Subject: [PATCH] From Jason Beverage, "Here is a fix for a small race condition in osgDB::makeDirectory. It attempts to create all the directories in the given path and stops attempting to make directories when one of them fails. I've added a check to see if the failure occurred b/c the directory was created by another thread or process. We were running into issues occasionally in osgEarth where multiple threads were writing out files like /1/2/3.jpg and /1/3/4.jpg. Both threads would try to create the /1 directory and only one of them would succeed. So the first thread would write out the full /1/2/3.jpg while the second thread wouldn't create the /1/3 directory b/c /1 was already created and the writing of /1/3/4.jpg would fail. " --- src/osgDB/FileUtils.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 7af1fbbde..1c3e4bc0e 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -214,8 +214,13 @@ bool osgDB::makeDirectory( const std::string &path ) if( mkdir( dir.c_str(), 0755 )< 0 ) #endif { - OSG_DEBUG << "osgDB::makeDirectory(): " << strerror(errno) << std::endl; - return false; + // Only return an error if the directory actually doesn't exist. It's possible that the directory was created + // by another thread or process + if (!osgDB::fileExists(dir)) + { + OSG_DEBUG << "osgDB::makeDirectory(): " << strerror(errno) << std::endl; + return false; + } } paths.pop(); }