protected FileStorage::createDirectory($directory, $mode = 0777, $is_backwards_recursive = FALSE)
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.
File
- core/lib/Drupal/Component/PhpStorage/FileStorage.php, line 155
Class
- FileStorage
- Stores the code as regular PHP files.
Namespace
Drupal\Component\PhpStorage
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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 ); } |
Please login to continue.