You are here

public function FileTransfer::findChroot in Drupal 10

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

Returns the chroot property for this connection.

It does this by moving up the tree until it finds itself

Return value

string|bool If successful, the chroot path for this connection, otherwise FALSE.

File

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

Class

FileTransfer
Defines the base FileTransfer class.

Namespace

Drupal\Core\FileTransfer

Code

public function findChroot() {

  // If the file exists as is, there is no chroot.
  $path = __FILE__;
  $path = $this
    ->fixRemotePath($path, FALSE);
  if ($this
    ->isFile($path)) {
    return FALSE;
  }
  $path = __DIR__;
  $path = $this
    ->fixRemotePath($path, FALSE);
  $parts = explode('/', $path);
  $chroot = '';
  while (count($parts)) {
    $check = implode('/', $parts);
    if ($this
      ->isFile($check . '/' . \Drupal::service('file_system')
      ->basename(__FILE__))) {

      // Remove the trailing slash.
      return substr($chroot, 0, -1);
    }
    $chroot .= array_shift($parts) . '/';
  }
  return FALSE;
}