You are here

protected function FileTransfer::copyDirectoryJailed in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/FileTransfer/FileTransfer.php \Drupal\Core\FileTransfer\FileTransfer::copyDirectoryJailed()
  2. 10 core/lib/Drupal/Core/FileTransfer/FileTransfer.php \Drupal\Core\FileTransfer\FileTransfer::copyDirectoryJailed()

Copies a directory.

We need a separate method to make sure the $destination is in the jail.

Parameters

string $source: The source path.

string $destination: The destination path.

1 call to FileTransfer::copyDirectoryJailed()
FileTransfer::copyDirectory in core/lib/Drupal/Core/FileTransfer/FileTransfer.php
Copies a directory.
1 method overrides FileTransfer::copyDirectoryJailed()
SSH::copyDirectoryJailed in core/lib/Drupal/Core/FileTransfer/SSH.php
Copies a directory.

File

core/lib/Drupal/Core/FileTransfer/FileTransfer.php, line 273

Class

FileTransfer
Defines the base FileTransfer class.

Namespace

Drupal\Core\FileTransfer

Code

protected function copyDirectoryJailed($source, $destination) {
  if ($this
    ->isDirectory($destination)) {
    $destination = $destination . '/' . \Drupal::service('file_system')
      ->basename($source);
  }
  $this
    ->createDirectory($destination);
  foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
    $relative_path = substr($filename, strlen($source));
    if ($file
      ->isDir()) {
      $this
        ->createDirectory($destination . $relative_path);
    }
    else {
      $this
        ->copyFile($file
        ->getPathName(), $destination . $relative_path);
    }
  }
}