private function GenerateTheme::copyRecursive in Drupal 9
Copies files recursively.
Parameters
string $src: A file or directory to be copied.
string $dest: Destination directory where the directory or file should be copied.
Throws
\RuntimeException Exception thrown if copying failed.
1 call to GenerateTheme::copyRecursive()
- GenerateTheme::execute in core/
lib/ Drupal/ Core/ Command/ GenerateTheme.php
File
- core/
lib/ Drupal/ Core/ Command/ GenerateTheme.php, line 213
Class
- GenerateTheme
- Generates a new theme based on latest default markup.
Namespace
Drupal\Core\CommandCode
private function copyRecursive($src, $dest) : void {
// Copy all subdirectories and files.
if (is_dir($src)) {
if (!mkdir($dest, FileSystem::CHMOD_DIRECTORY, FALSE)) {
throw new \RuntimeException("Directory {$dest} could not be created");
}
$handle = opendir($src);
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
$this
->copyRecursive("{$src}/{$file}", "{$dest}/{$file}");
}
}
closedir($handle);
}
elseif (is_link($src)) {
symlink(readlink($src), $dest);
}
elseif (!copy($src, $dest)) {
throw new \RuntimeException("File {$src} could not be copied to {$dest}");
}
// Set permissions for the directory or file.
if (!is_link($dest)) {
if (is_dir($dest)) {
$mode = FileSystem::CHMOD_DIRECTORY;
}
else {
$mode = FileSystem::CHMOD_FILE;
}
if (!chmod($dest, $mode)) {
throw new \RuntimeException("The file permissions could not be set on {$src}");
}
}
}