function GenerateTheme::copyRecursive

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 302

Class

GenerateTheme
Generates a new theme based on latest default markup.

Namespace

Drupal\Core\Command

Code

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}");
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.