From 5b5de2c74338119c1565f68ad3225caad240a31b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 4 Feb 2012 09:38:23 +0100 Subject: [PATCH] fixed the creation of the cache directory in case of a race condition (closes #620) --- CHANGELOG | 2 +- lib/Twig/Environment.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1eeaac0..9a7b8d2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 1.7.0-DEV - * n/a + * fixed the creation of the cache directory in case of a race condition * 1.6.0 (2012-02-04) diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 6a84e83..165430b 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -1036,8 +1036,13 @@ class Twig_Environment protected function writeCacheFile($file, $content) { - if (!is_dir(dirname($file))) { - mkdir(dirname($file), 0777, true); + $dir = dirname($file); + if (!is_dir($dir)) { + if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) { + throw new RuntimeException(sprintf("Unable to create the cache directory (%s).", $dir)); + } + } elseif (!is_writable($dir)) { + throw new RuntimeException(sprintf("Unable to write in the cache directory (%s).", $dir)); } $tmpFile = tempnam(dirname($file), basename($file)); -- 1.7.2.5