3 namespace Drupal\Core\FileTransfer;
6 * Defines the local connection class for copying files as the httpd user.
8 class Local extends FileTransfer implements ChmodInterface {
13 public function connect() {
20 public static function factory($jail, $settings) {
21 return new Local($jail);
27 protected function copyFileJailed($source, $destination) {
28 if (@!copy($source, $destination)) {
29 throw new FileTransferException('Cannot copy %source to %destination.', NULL, ['%source' => $source, '%destination' => $destination]);
36 protected function createDirectoryJailed($directory) {
37 if (!is_dir($directory) && @!mkdir($directory, 0777, TRUE)) {
38 throw new FileTransferException('Cannot create directory %directory.', NULL, ['%directory' => $directory]);
45 protected function removeDirectoryJailed($directory) {
46 if (!is_dir($directory)) {
47 // Programmer error assertion, not something we expect users to see.
48 throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', NULL, ['%directory' => $directory]);
50 foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) {
52 if (@!drupal_rmdir($filename)) {
53 throw new FileTransferException('Cannot remove directory %directory.', NULL, ['%directory' => $filename]);
56 elseif ($file->isFile()) {
57 if (@!drupal_unlink($filename)) {
58 throw new FileTransferException('Cannot remove file %file.', NULL, ['%file' => $filename]);
62 if (@!drupal_rmdir($directory)) {
63 throw new FileTransferException('Cannot remove directory %directory.', NULL, ['%directory' => $directory]);
70 protected function removeFileJailed($file) {
71 if (@!drupal_unlink($file)) {
72 throw new FileTransferException('Cannot remove file %file.', NULL, ['%file' => $file]);
79 public function isDirectory($path) {
86 public function isFile($path) {
87 return is_file($path);
93 public function chmodJailed($path, $mode, $recursive) {
94 if ($recursive && is_dir($path)) {
95 foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
96 if (@!chmod($filename, $mode)) {
97 throw new FileTransferException('Cannot chmod %path.', NULL, ['%path' => $filename]);
101 elseif (@!chmod($path, $mode)) {
102 throw new FileTransferException('Cannot chmod %path.', NULL, ['%path' => $path]);