Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Commit

Permalink
fixes zendframework/zendframework#6435: Race Condition in filesystem …
Browse files Browse the repository at this point in the history
…cache on prepare directory structure
  • Loading branch information
marc-mabe authored and Ocramius committed Nov 22, 2014
1 parent e934413 commit 72ee3ab
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1413,8 +1413,16 @@ protected function prepareDirectoryStructure($file)
}

if (!$res) {
$oct = ($perm === false) ? '777' : decoct($perm);
$err = ErrorHandler::stop();

// Issue 6435:
// mkdir could fail because of a race condition it was already created by another process
// after the first file_exists above
if (file_exists($pathname)) {
return;
}

$oct = ($perm === false) ? '777' : decoct($perm);
throw new Exception\RuntimeException("mkdir('{$pathname}', 0{$oct}, true) failed", 0, $err);
}

Expand Down Expand Up @@ -1452,6 +1460,14 @@ protected function prepareDirectoryStructure($file)
}

if (!$res) {

// Issue 6435:
// mkdir could fail because of a race condition it was already created by another process
// after the first file_exists above ... go to the next path part.
if (file_exists($path)) {
continue;
}

$oct = ($perm === false) ? '777' : decoct($perm);
ErrorHandler::stop();
throw new Exception\RuntimeException(
Expand Down

0 comments on commit 72ee3ab

Please sign in to comment.