Skip to content

Commit 6d46a18

Browse files
committed
bug symfony#16292 fix race condition at mkdir (symfony#16258) (ewgRa)
This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes symfony#16292). Discussion ---------- fix race condition at mkdir (symfony#16258) | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#16258 | License | MIT | Doc PR | Commits ------- 2c2836c fix race condition at mkdir (symfony#16258)
2 parents 4f7fd74 + 2c2836c commit 6d46a18

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/Symfony/Component/HttpKernel/HttpCache/Store.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ class Store implements StoreInterface
3232
* Constructor.
3333
*
3434
* @param string $root The path to the cache directory
35+
*
36+
* @throws \RuntimeException
3537
*/
3638
public function __construct($root)
3739
{
3840
$this->root = $root;
3941
if (!is_dir($this->root)) {
40-
mkdir($this->root, 0777, true);
42+
if (false === @mkdir($this->root, 0777, true) && !is_dir($this->root)) {
43+
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
44+
}
4145
}
4246
$this->keyCache = new \SplObjectStorage();
4347
$this->locks = array();
@@ -74,7 +78,7 @@ public function cleanup()
7478
public function lock(Request $request)
7579
{
7680
$path = $this->getPath($this->getCacheKey($request).'.lck');
77-
if (!is_dir(dirname($path)) && false === @mkdir(dirname($path), 0777, true)) {
81+
if (!is_dir(dirname($path)) && false === @mkdir(dirname($path), 0777, true) && !is_dir(dirname($path))) {
7882
return false;
7983
}
8084

@@ -338,7 +342,7 @@ private function load($key)
338342
private function save($key, $data)
339343
{
340344
$path = $this->getPath($key);
341-
if (!is_dir(dirname($path)) && false === @mkdir(dirname($path), 0777, true)) {
345+
if (!is_dir(dirname($path)) && false === @mkdir(dirname($path), 0777, true) && !is_dir(dirname($path))) {
342346
return false;
343347
}
344348

src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function __construct($dsn)
4141
}
4242
$this->folder = substr($dsn, 5);
4343

44-
if (!is_dir($this->folder)) {
45-
mkdir($this->folder, 0777, true);
44+
if (!is_dir($this->folder) && false === @mkdir($this->folder, 0777, true) && !is_dir($this->folder)) {
45+
throw new \RuntimeException(sprintf('Unable to create the storage directory (%s).', $this->folder));
4646
}
4747
}
4848

@@ -125,6 +125,8 @@ public function read($token)
125125

126126
/**
127127
* {@inheritdoc}
128+
*
129+
* @throws \RuntimeException
128130
*/
129131
public function write(Profile $profile)
130132
{
@@ -134,8 +136,8 @@ public function write(Profile $profile)
134136
if (!$profileIndexed) {
135137
// Create directory
136138
$dir = dirname($file);
137-
if (!is_dir($dir)) {
138-
mkdir($dir, 0777, true);
139+
if (!is_dir($dir) && false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
140+
throw new \RuntimeException(sprintf('Unable to create the storage directory (%s).', $dir));
139141
}
140142
}
141143

0 commit comments

Comments
 (0)