bug #2262 Call clearstatcache() before calling is_dir(). (hanabokuro)

This PR was submitted for the master branch but it was merged into the 1.x branch instead (closes #2262).

Discussion
----------

Call clearstatcache() before calling is_dir().

The result of is_dir() is cached.
So call clearstatcache() before calling 2nd is_dir().

Commits
-------

96638c0d Call clearstatcache() before calling is_dir().
This commit is contained in:
Fabien Potencier
2017-03-22 08:05:13 -07:00
+5 -2
View File
@@ -49,8 +49,11 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
{
$dir = dirname($key);
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));
if (false === @mkdir($dir, 0777, true)) {
clearstatcache(true, $dir);
if (!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));