From 47dc56356a3ad2ce0af8a1ac57f5cae87201c2db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20K=C5=99=C3=AD=C5=BE?= Date: Sat, 3 Sep 2016 11:41:23 +0200 Subject: [PATCH] FileSystem: fix mkdir race condition (#120) --- src/Utils/FileSystem.php | 4 ++-- tests/Utils/FileSystem.phpt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Utils/FileSystem.php b/src/Utils/FileSystem.php index 14771399f..5402d0fc8 100644 --- a/src/Utils/FileSystem.php +++ b/src/Utils/FileSystem.php @@ -24,8 +24,8 @@ class FileSystem */ public static function createDir($dir, $mode = 0777) { - if (!is_dir($dir) && !@mkdir($dir, $mode, TRUE)) { // intentionally @; not atomic - throw new Nette\IOException("Unable to create directory '$dir'."); + if (!is_dir($dir) && !@mkdir($dir, $mode, TRUE) && !is_dir($dir)) { // @ - dir may already exist + throw new Nette\IOException("Unable to create directory '$dir'. " . error_get_last()['message']); } } diff --git a/tests/Utils/FileSystem.phpt b/tests/Utils/FileSystem.phpt index 75be57c11..68a69dbe9 100644 --- a/tests/Utils/FileSystem.phpt +++ b/tests/Utils/FileSystem.phpt @@ -21,7 +21,7 @@ test(function () { // createDir Assert::exception(function () { FileSystem::createDir(''); -}, Nette\IOException::class, "Unable to create directory ''."); +}, Nette\IOException::class, "Unable to create directory ''.%A%"); test(function () { // write + read @@ -32,7 +32,7 @@ test(function () { // write + read Assert::exception(function () { FileSystem::write('', 'Hello'); -}, Nette\IOException::class, "Unable to create directory ''."); +}, Nette\IOException::class, "Unable to create directory ''.%A%"); Assert::exception(function () { FileSystem::read('');