1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-11 16:49:42 +01:00

Merge branch '2.0'

This commit is contained in:
terrafrost 2017-06-12 21:26:20 -05:00
commit 03ca09a104

View File

@ -162,7 +162,7 @@ class SFTP extends SSH2
* Current working directory
*
* @var string
* @see self::_realpath()
* @see self::realpath()
* @see self::chdir()
* @access private
*/
@ -240,6 +240,20 @@ class SFTP extends SSH2
*/
private $sortOptions = [];
/**
* Canonicalization Flag
*
* Determines whether or not paths should be canonicalized before being
* passed on to the remote server.
*
* @see self::enablePathCanonicalization()
* @see self::disablePathCanonicalization()
* @see self::realpath()
* @var bool
* @access private
*/
private $canonicalize_paths = true;
/**
* Default Constructor.
*
@ -579,6 +593,26 @@ class SFTP extends SSH2
$this->stat_cache = [];
}
/**
* Enable path canonicalization
*
* @access public
*/
public function enablePathCanonicalization()
{
$this->canonicalize_paths = true;
}
/**
* Enable path canonicalization
*
* @access public
*/
public function disablePathCanonicalization()
{
$this->canonicalize_paths = false;
}
/**
* Returns the current directory name
*
@ -622,7 +656,10 @@ class SFTP extends SSH2
* SFTP doesn't provide a mechanism by which the current working directory can be changed, so we'll emulate it. Returns
* the absolute (canonicalized) path.
*
* If canonicalize_paths has been disabled using disablePathCanonicalization(), $path is returned as-is.
*
* @see self::chdir()
* @see self::disablePathCanonicalization()
* @param string $path
* @throws \UnexpectedValueException on receipt of unexpected packets
* @return mixed
@ -630,6 +667,10 @@ class SFTP extends SSH2
*/
public function realpath($path)
{
if (!$this->canonicalize_paths) {
return $path;
}
if ($this->pwd === false) {
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.9
if (!$this->send_sftp_packet(NET_SFTP_REALPATH, pack('Na*', strlen($path), $path))) {
@ -1282,7 +1323,7 @@ class SFTP extends SSH2
/**
* Returns general information about a file or symbolic link
*
* Determines information without calling \phpseclib\Net\SFTP::_realpath().
* Determines information without calling \phpseclib\Net\SFTP::realpath().
* The second parameter can be either NET_SFTP_STAT or NET_SFTP_LSTAT.
*
* @param string $filename
@ -1444,7 +1485,7 @@ class SFTP extends SSH2
return true;
}
$filename = $this->realPath($filename);
$filename = $this->realpath($filename);
// rather than return what the permissions *should* be, we'll return what they actually are. this will also
// tell us if the file actually exists.
// incidentally, SFTPv4+ adds an additional 32-bit integer field - flags - to the following: