From b7f55e48a7787a8331f863975f6225c0148d6599 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Wed, 13 Aug 2014 20:33:33 +0200 Subject: [PATCH] fixes zendframework/zf2#6435: Race Condition in filesystem cache on prepare directory structure --- src/Storage/Adapter/Filesystem.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Storage/Adapter/Filesystem.php b/src/Storage/Adapter/Filesystem.php index b46f5a2..eb594f1 100644 --- a/src/Storage/Adapter/Filesystem.php +++ b/src/Storage/Adapter/Filesystem.php @@ -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); } @@ -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(