You are here

public function Local::chmodJailed in Drupal 10

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

Changes the permissions of the file / directory specified in $path.

Parameters

string $path: Path to change permissions of.

int $mode: The new file permission mode to be passed to chmod().

bool $recursive: Pass TRUE to recursively chmod the entire directory specified in $path.

Overrides ChmodInterface::chmodJailed

See also

http://php.net/chmod

File

core/lib/Drupal/Core/FileTransfer/Local.php, line 115

Class

Local
Defines the local connection class for copying files as the httpd user.

Namespace

Drupal\Core\FileTransfer

Code

public function chmodJailed($path, $mode, $recursive) {
  if ($recursive && is_dir($path)) {
    foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
      if (@(!chmod($filename, $mode))) {
        throw new FileTransferException('Cannot chmod %path.', 0, [
          '%path' => $filename,
        ]);
      }
    }
  }
  elseif (@(!chmod($path, $mode))) {
    throw new FileTransferException('Cannot chmod %path.', 0, [
      '%path' => $path,
    ]);
  }
}