Skip to content
Snippets Groups Projects
Commit a0d46cde authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Resolve race condition around temp directory creation

It's possible that isdir(temp_dir) will be false and then a mkpath()
call will fail because some other thread came in and crated the
directory at that very moment - so save errno if mkdir fails and
call isdir() again to double-check that the directory wasn't created
by someone else already.
parent 1670393a
No related branches found
No related tags found
No related merge requests found
......@@ -347,8 +347,11 @@ int md(const char* inpath)
*p = '\0';
if(!isdir(path)) {
if(mkpath(path) != 0)
return errno;
if(mkpath(path) != 0) {
int result = errno;
if(!isdir(path)) // race condition: did another thread make the directory already?
return result;
}
}
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment