function Local::removeDirectoryJailed
Same name in other branches
- 9 core/lib/Drupal/Core/FileTransfer/Local.php \Drupal\Core\FileTransfer\Local::removeDirectoryJailed()
- 10 core/lib/Drupal/Core/FileTransfer/Local.php \Drupal\Core\FileTransfer\Local::removeDirectoryJailed()
- 11.x core/lib/Drupal/Core/FileTransfer/Local.php \Drupal\Core\FileTransfer\Local::removeDirectoryJailed()
Overrides FileTransfer::removeDirectoryJailed
File
-
core/
lib/ Drupal/ Core/ FileTransfer/ Local.php, line 69
Class
- Local
- Defines the local connection class for copying files as the httpd user.
Namespace
Drupal\Core\FileTransferCode
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.', NULL, [
'%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.', NULL, [
'%directory' => $filename,
]);
}
}
elseif ($file->isFile()) {
if (@(!$this->fileSystem
->unlink($filename))) {
throw new FileTransferException('Cannot remove file %file.', NULL, [
'%file' => $filename,
]);
}
}
}
if (@(!$file_system->rmdir($directory))) {
throw new FileTransferException('Cannot remove directory %directory.', NULL, [
'%directory' => $directory,
]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.