Loading core/lib/Drupal/Core/FileTransfer/FileTransfer.php +62 −4 Original line number Diff line number Diff line Loading @@ -41,6 +41,27 @@ abstract class FileTransfer { */ protected $port; /** * Full path to directory where file-transfer is restricted to. * * @var string */ protected $jail; /** * Path to connection chroot. * * @var string|false|null */ private $chrootPath; /** * The instantiated connection object. * * @var object|false|null */ private $connectionHandle; /** * Constructs a Drupal\Core\FileTransfer\FileTransfer object. * Loading Loading @@ -93,12 +114,49 @@ public static function factory($jail, $settings) { public function __get($name) { if ($name == 'connection') { $this->connect(); return $this->connection; return $this->connectionHandle; } if ($name == 'chroot') { $this->setChroot(); return $this->chroot; return $this->chrootPath; } } /** * {@inheritdoc} */ public function __set(string $name, $value): void { if ($name == 'connection') { $this->connectionHandle = $value; } elseif ($name == 'chroot') { $this->chrootPath = $value; } } /** * {@inheritdoc} */ public function __isset(string $name): bool { if ($name == 'connection') { return isset($this->connectionHandle); } if ($name == 'chroot') { return isset($this->chrootPath); } return FALSE; } /** * {@inheritdoc} */ public function __unset(string $name): void { if ($name == 'connection') { unset($this->connectionHandle); } elseif ($name == 'chroot') { unset($this->chrootPath); } } Loading Loading @@ -235,8 +293,8 @@ final protected function fixRemotePath($path, $strip_chroot = TRUE) { // Strip out windows drive letter if its there. $path = preg_replace('|^([a-z]{1}):|i', '', $path); if ($strip_chroot) { if ($this->chroot && strpos($path, $this->chroot) === 0) { $path = ($path == $this->chroot) ? '' : substr($path, strlen($this->chroot)); if ($this->chrootPath && strpos($path, $this->chrootPath) === 0) { $path = ($path == $this->chrootPath) ? '' : substr($path, strlen($this->chrootPath)); } } return $path; Loading core/modules/system/tests/src/Functional/FileTransfer/TestFileTransfer.php +3 −2 Original line number Diff line number Diff line Loading @@ -45,8 +45,9 @@ public static function factory($jail, $settings) { } public function connect() { $this->connection = new MockTestConnection(); $this->connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/"; $connection = new MockTestConnection(); $connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/"; $this->connection = $connection; } public function copyFileJailed($source, $destination) { Loading Loading
core/lib/Drupal/Core/FileTransfer/FileTransfer.php +62 −4 Original line number Diff line number Diff line Loading @@ -41,6 +41,27 @@ abstract class FileTransfer { */ protected $port; /** * Full path to directory where file-transfer is restricted to. * * @var string */ protected $jail; /** * Path to connection chroot. * * @var string|false|null */ private $chrootPath; /** * The instantiated connection object. * * @var object|false|null */ private $connectionHandle; /** * Constructs a Drupal\Core\FileTransfer\FileTransfer object. * Loading Loading @@ -93,12 +114,49 @@ public static function factory($jail, $settings) { public function __get($name) { if ($name == 'connection') { $this->connect(); return $this->connection; return $this->connectionHandle; } if ($name == 'chroot') { $this->setChroot(); return $this->chroot; return $this->chrootPath; } } /** * {@inheritdoc} */ public function __set(string $name, $value): void { if ($name == 'connection') { $this->connectionHandle = $value; } elseif ($name == 'chroot') { $this->chrootPath = $value; } } /** * {@inheritdoc} */ public function __isset(string $name): bool { if ($name == 'connection') { return isset($this->connectionHandle); } if ($name == 'chroot') { return isset($this->chrootPath); } return FALSE; } /** * {@inheritdoc} */ public function __unset(string $name): void { if ($name == 'connection') { unset($this->connectionHandle); } elseif ($name == 'chroot') { unset($this->chrootPath); } } Loading Loading @@ -235,8 +293,8 @@ final protected function fixRemotePath($path, $strip_chroot = TRUE) { // Strip out windows drive letter if its there. $path = preg_replace('|^([a-z]{1}):|i', '', $path); if ($strip_chroot) { if ($this->chroot && strpos($path, $this->chroot) === 0) { $path = ($path == $this->chroot) ? '' : substr($path, strlen($this->chroot)); if ($this->chrootPath && strpos($path, $this->chrootPath) === 0) { $path = ($path == $this->chrootPath) ? '' : substr($path, strlen($this->chrootPath)); } } return $path; Loading
core/modules/system/tests/src/Functional/FileTransfer/TestFileTransfer.php +3 −2 Original line number Diff line number Diff line Loading @@ -45,8 +45,9 @@ public static function factory($jail, $settings) { } public function connect() { $this->connection = new MockTestConnection(); $this->connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/"; $connection = new MockTestConnection(); $connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/"; $this->connection = $connection; } public function copyFileJailed($source, $destination) { Loading