/**
* {@inheritdoc}
*/
protected function removeDirectoryJailed($directory) { if (!
is_dir($directory)) { // Programmer error assertion, not something we expect users to see.
throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', 0,
['%directory' =>
$directory]);
} /** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::
service('file_system'
);
foreach (new \
RecursiveIteratorIterator(new \
RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS
), \RecursiveIteratorIterator::CHILD_FIRST
) as $filename =>
$file) { if ($file->
isDir()) { if (@!
$file_system->
rmdir($filename)) { throw new FileTransferException('Cannot remove directory %directory.', 0,
['%directory' =>
$filename]);
} } elseif ($file->
isFile()) { if (@!
$this->fileSystem->
unlink($filename)) { throw new FileTransferException('Cannot remove file %file.', 0,
['%file' =>
$filename]);
} } }