Skip to content

Commit

Permalink
Merge pull request #747 from malarzm/andrey-tech-issue_744
Browse files Browse the repository at this point in the history
Fix mkdir() race condition
  • Loading branch information
malarzm authored Sep 19, 2022
2 parents c1c31fa + 6f8d5e9 commit fac3273
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CacheWarmer/HydratorCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function assert;
use function dirname;
use function file_exists;
use function is_dir;
use function is_writable;
use function mkdir;
use function sprintf;
Expand Down Expand Up @@ -58,7 +59,7 @@ public function warmUp($cacheDir)
// we need the directory no matter the hydrator cache generation strategy.
$hydratorCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.hydrator_dir');
if (! file_exists($hydratorCacheDir)) {
if (@mkdir($hydratorCacheDir, 0775, true) === false) {
if (@mkdir($hydratorCacheDir, 0775, true) === false && ! is_dir($hydratorCacheDir)) {
throw new RuntimeException(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir)));
}
} elseif (! is_writable($hydratorCacheDir)) {
Expand Down
3 changes: 2 additions & 1 deletion CacheWarmer/PersistentCollectionCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function dirname;
use function file_exists;
use function in_array;
use function is_dir;
use function is_writable;
use function mkdir;
use function sprintf;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function warmUp($cacheDir)
// we need the directory no matter the hydrator cache generation strategy.
$collCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.persistent_collection_dir');
if (! file_exists($collCacheDir)) {
if (@mkdir($collCacheDir, 0775, true) === false) {
if (@mkdir($collCacheDir, 0775, true) === false && ! is_dir($collCacheDir)) {
throw new RuntimeException(sprintf('Unable to create the Doctrine persistent collection directory (%s)', dirname($collCacheDir)));
}
} elseif (! is_writable($collCacheDir)) {
Expand Down
3 changes: 2 additions & 1 deletion CacheWarmer/ProxyCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function assert;
use function dirname;
use function file_exists;
use function is_dir;
use function is_writable;
use function mkdir;
use function sprintf;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function warmUp($cacheDir)
// we need the directory no matter the proxy cache generation strategy.
$proxyCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.proxy_dir');
if (! file_exists($proxyCacheDir)) {
if (@mkdir($proxyCacheDir, 0775, true) === false) {
if (@mkdir($proxyCacheDir, 0775, true) === false && ! is_dir($proxyCacheDir)) {
throw new RuntimeException(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir)));
}
} elseif (! is_writable($proxyCacheDir)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function process(ContainerBuilder $container)
// Create document proxy directory
$hydratorCacheDir = (string) $container->getParameter('doctrine_mongodb.odm.hydrator_dir');
if (! is_dir($hydratorCacheDir)) {
if (@mkdir($hydratorCacheDir, 0775, true) === false) {
if (@mkdir($hydratorCacheDir, 0775, true) === false && ! is_dir($hydratorCacheDir)) {
throw new RuntimeException(
sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir))
);
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/CreateProxyDirectoryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function process(ContainerBuilder $container)
// Create document proxy directory
$proxyCacheDir = (string) $container->getParameter('doctrine_mongodb.odm.proxy_dir');
if (! is_dir($proxyCacheDir)) {
if (@mkdir($proxyCacheDir, 0775, true) === false) {
if (@mkdir($proxyCacheDir, 0775, true) === false && ! is_dir($proxyCacheDir)) {
throw new RuntimeException(
sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir))
);
Expand Down

0 comments on commit fac3273

Please sign in to comment.