bug #16292 fix race condition at mkdir (#16258) (ewgRa)

This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #16292).

Discussion
----------

fix race condition at mkdir (#16258)

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16258
| License       | MIT
| Doc PR        |

Commits
-------

2c2836c fix race condition at mkdir (#16258)
This commit is contained in:
Fabien Potencier 2015-11-07 09:38:45 +01:00
commit 6d46a186a6
2 changed files with 13 additions and 7 deletions

View File

@ -32,12 +32,16 @@ class Store implements StoreInterface
* Constructor.
*
* @param string $root The path to the cache directory
*
* @throws \RuntimeException
*/
public function __construct($root)
{
$this->root = $root;
if (!is_dir($this->root)) {
mkdir($this->root, 0777, true);
if (false === @mkdir($this->root, 0777, true) && !is_dir($this->root)) {
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
}
}
$this->keyCache = new \SplObjectStorage();
$this->locks = array();
@ -74,7 +78,7 @@ class Store implements StoreInterface
public function lock(Request $request)
{
$path = $this->getPath($this->getCacheKey($request).'.lck');
if (!is_dir(dirname($path)) && false === @mkdir(dirname($path), 0777, true)) {
if (!is_dir(dirname($path)) && false === @mkdir(dirname($path), 0777, true) && !is_dir(dirname($path))) {
return false;
}
@ -338,7 +342,7 @@ class Store implements StoreInterface
private function save($key, $data)
{
$path = $this->getPath($key);
if (!is_dir(dirname($path)) && false === @mkdir(dirname($path), 0777, true)) {
if (!is_dir(dirname($path)) && false === @mkdir(dirname($path), 0777, true) && !is_dir(dirname($path))) {
return false;
}

View File

@ -41,8 +41,8 @@ class FileProfilerStorage implements ProfilerStorageInterface
}
$this->folder = substr($dsn, 5);
if (!is_dir($this->folder)) {
mkdir($this->folder, 0777, true);
if (!is_dir($this->folder) && false === @mkdir($this->folder, 0777, true) && !is_dir($this->folder)) {
throw new \RuntimeException(sprintf('Unable to create the storage directory (%s).', $this->folder));
}
}
@ -125,6 +125,8 @@ class FileProfilerStorage implements ProfilerStorageInterface
/**
* {@inheritdoc}
*
* @throws \RuntimeException
*/
public function write(Profile $profile)
{
@ -134,8 +136,8 @@ class FileProfilerStorage implements ProfilerStorageInterface
if (!$profileIndexed) {
// Create directory
$dir = dirname($file);
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
if (!is_dir($dir) && false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
throw new \RuntimeException(sprintf('Unable to create the storage directory (%s).', $dir));
}
}