You are here

protected function FileStorage::createDirectory in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Component/PhpStorage/FileStorage.php \Drupal\Component\PhpStorage\FileStorage::createDirectory()

Ensures the requested directory exists and has the right permissions.

For compatibility with open_basedir, the requested directory is created using a recursion logic that is based on the relative directory path/tree: It works from the end of the path recursively back towards the root directory, until an existing parent directory is found. From there, the subdirectories are created.

Parameters

string $directory: The directory path.

int $mode: The mode, permissions, the directory should have.

bool $is_backwards_recursive: Internal use only.

Return value

bool TRUE if the directory exists or has been created, FALSE otherwise.

1 call to FileStorage::createDirectory()
FileStorage::ensureDirectory in core/lib/Drupal/Component/PhpStorage/FileStorage.php
Ensures the directory exists, has the right permissions, and a .htaccess.

File

core/lib/Drupal/Component/PhpStorage/FileStorage.php, line 160
Contains \Drupal\Component\PhpStorage\FileStorage.

Class

FileStorage
Stores the code as regular PHP files.

Namespace

Drupal\Component\PhpStorage

Code

protected function createDirectory($directory, $mode = 0777, $is_backwards_recursive = FALSE) {

  // 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.
  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 ($status = mkdir($directory)) {

      // Only try to chmod() if the subdirectory could be created.
      $status = chmod($directory, $mode);
    }
    return $is_backwards_recursive ? TRUE : $status;
  }

  // If the parent directory and the requested 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. Only if that recursion succeeds, create the final,
  // originally requested subdirectory.
  return $this
    ->createDirectory($parent, $mode, TRUE) && mkdir($directory) && chmod($directory, $mode);
}