Skip to content

Commit

Permalink
fix race condition at mkdir (#16258)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewgRa authored and fabpot committed Nov 7, 2015
1 parent 4f7fd74 commit 2c2836c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/Symfony/Component/HttpKernel/HttpCache/Store.php
Expand Up @@ -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();
Expand Down Expand Up @@ -74,7 +78,7 @@ public function cleanup()
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;
}

Expand Down Expand Up @@ -338,7 +342,7 @@ private function load($key)
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;
}

Expand Down
Expand Up @@ -41,8 +41,8 @@ public function __construct($dsn)
}
$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));
}
}

Expand Down Expand Up @@ -125,6 +125,8 @@ public function read($token)

/**
* {@inheritdoc}
*
* @throws \RuntimeException
*/
public function write(Profile $profile)
{
Expand All @@ -134,8 +136,8 @@ public function write(Profile $profile)
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));
}
}

Expand Down

0 comments on commit 2c2836c

Please sign in to comment.