You are here

protected function FileStorage::ensureStorage in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Config/FileStorage.php \Drupal\Core\Config\FileStorage::ensureStorage()
  2. 9 core/lib/Drupal/Core/Config/FileStorage.php \Drupal\Core\Config\FileStorage::ensureStorage()

Check if the directory exists and create it if not.

File

core/lib/Drupal/Core/Config/FileStorage.php, line 78

Class

FileStorage
Defines the file storage.

Namespace

Drupal\Core\Config

Code

protected function ensureStorage() {
  $dir = $this
    ->getCollectionDirectory();
  $success = $this
    ->getFileSystem()
    ->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);

  // Only create .htaccess file in root directory.
  if ($dir == $this->directory) {
    $success = $success && FileSecurity::writeHtaccess($this->directory);
  }
  if (!$success) {
    throw new StorageException('Failed to create config directory ' . $dir);
  }
  return $this;
}