MDL-40891 work around make_writable_directory() race condition

You will still get a "PHP Warning:  mkdir(): File exists" but that should not cause any problems on production sites.
This commit is contained in:
Petr Škoda
2013-07-26 20:29:55 +02:00
parent f171a8c06e
commit 7a8ef1453e
+9 -4
View File
@@ -1260,10 +1260,15 @@ function make_writable_directory($dir, $exceptiononerror = true) {
if (!file_exists($dir)) {
if (!mkdir($dir, $CFG->directorypermissions, true)) {
if ($exceptiononerror) {
throw new invalid_dataroot_permissions($dir.' can not be created, check permissions.');
} else {
return false;
clearstatcache();
// There might be a race condition when creating directory.
if (!is_dir($dir)) {
if ($exceptiononerror) {
throw new invalid_dataroot_permissions($dir.' can not be created, check permissions.');
} else {
debugging('Can not create directory: '.$dir, DEBUG_DEVELOPER);
return false;
}
}
}
}