From 7a8ef1453eb3c0f60d5cdfd36716e5e1f5f67ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Fri, 26 Jul 2013 20:27:36 +0200 Subject: [PATCH] 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. --- lib/setuplib.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/setuplib.php b/lib/setuplib.php index e120a909661..06178412317 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -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; + } } } }