diff -u b/core/lib/Drupal/Component/PhpStorage/FileStorage.php b/core/lib/Drupal/Component/PhpStorage/FileStorage.php --- b/core/lib/Drupal/Component/PhpStorage/FileStorage.php +++ b/core/lib/Drupal/Component/PhpStorage/FileStorage.php @@ -76,17 +76,25 @@ */ protected function ensureDirectory($directory, $mode = 0777) { // If the directory exists already, there's nothing to do. + if (is_dir($directory)) { + return TRUE; + } // Otherwise, try to create the directory and ensure to set its permissions, // because mkdir() obeys the umask of the current process. - $parent = dirname($directory); - if (is_dir($directory) || (is_dir($parent) && mkdir($directory) && chmod($directory, $mode))) { + if (is_dir($parent = dirname($directory))) { + // If the parent directory exists, then the backwards recursion must end, + // regardless of whether the subdirectory could be created. + if (mkdir($directory)) { + // Only try to chmod() if the subdirectory could be created. + chmod($directory, $mode); + } return TRUE; } // If the directory does not exist and could not be created above, walk the // requested directory path back up until an existing directory is hit, and // from there, recursively create the sub-directories. If that recursion // succeeds, create the final subdirectory. - return $this->ensureDirectory($parent, $mode) && mkdir($directory); + return $this->ensureDirectory($parent, $mode) && mkdir($directory) && chmod($directory, $mode); } /**