diff --git a/core/lib/Drupal/Component/PhpStorage/FileStorage.php b/core/lib/Drupal/Component/PhpStorage/FileStorage.php index 8ddf101..6853356 100644 --- a/core/lib/Drupal/Component/PhpStorage/FileStorage.php +++ b/core/lib/Drupal/Component/PhpStorage/FileStorage.php @@ -7,9 +7,6 @@ namespace Drupal\Component\PhpStorage; -use \RecursiveDirectoryIterator; -use \RecursiveIteratorIterator; - /** * Stores the code as regular PHP files. */ @@ -87,9 +84,9 @@ public function writeable() { */ public function deleteAll() { if (is_dir($this->directory)) { - $iterator = new RecursiveDirectoryIterator($this->directory); - foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) { - if (!$file->isDot()) { + $iterator = new \RecursiveDirectoryIterator($this->directory); + foreach (new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) { + if (!$iterator->isDot()) { $this->filePreDeleteCallback($file->getPathname()); if ($file->isDir()) { rmdir($file->getPathname()); diff --git a/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php b/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php index 3ace078..4d564fb 100644 --- a/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php +++ b/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php @@ -42,6 +42,11 @@ class MTimeProtectedFastFileStorage extends FileStorage { /** + * The .htaccess code to make a directory private. + */ + const HTACCESS="SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nDeny from all\nOptions None\nOptions +FollowSymLinks"; + + /** * The secret used in the HMAC. * * @var string @@ -145,7 +150,10 @@ protected function ensureDirectory() { mkdir($this->directory, 0700, TRUE); } chmod($this->directory, 0700); - $this->saveHtaccess($this->directory); + $htaccess_path = $this->directory . '/.htaccess'; + if (!file_exists($htaccess_path) && file_put_contents($htaccess_path, self::HTACCESS)) { + @chmod($htaccess_path, 0444); + } } /** @@ -210,29 +218,4 @@ protected function getUncachedMTime($directory) { return filemtime($directory); } - /** - * Creates a .htaccess file in the given directory to make it private. - * - * @see file_save_htaccess() - * - * @param string $directory - * The directory. - */ - protected function saveHtaccess($directory) { - $directory = rtrim($directory, '/\\'); - $htaccess_path = $directory . '/.htaccess'; - - if (file_exists($htaccess_path)) { - // Short circuit if the .htaccess file already exists. - return; - } - - // Private .htaccess file. - $htaccess_lines = "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nDeny from all\nOptions None\nOptions +FollowSymLinks"; - - // Write the .htaccess file. - if (file_put_contents($htaccess_path, $htaccess_lines)) { - chmod($htaccess_path, 0444); - } - } }