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

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#6573-zend-cache-file…
Browse files Browse the repository at this point in the history
…system-race-conditions-fixes-for-zendframework/zf2#6435' into develop

Close zendframework/zendframework#6573
Close zendframework/zendframework#6435
Forward port zendframework/zendframework#6573
Forward port zendframework/zendframework#6435
  • Loading branch information
Ocramius committed Nov 22, 2014
2 parents b53b632 + 72ee3ab commit 287459c
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 287459c

Please sign in to comment.