Skip to content

Commit

Permalink
FileSystem: fix mkdir race condition (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepakriz authored and dg committed Sep 3, 2016
1 parent 3b239d7 commit 47dc563
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Utils/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Utils/FileSystem.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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('');
Expand Down

0 comments on commit 47dc563

Please sign in to comment.