From 893695d7f30bb6cba72ec033a06e3ab75957cc54 Mon Sep 17 00:00:00 2001 From: Jim Wigginton Date: Wed, 1 Jun 2011 01:51:47 +0000 Subject: [PATCH] - stat() and lstat() now return information on the file type git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@162 21d32557-59b3-4da0-833f-c5933fad653e --- phpseclib/Net/SFTP.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 105f6611..e39dd715 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -771,7 +771,7 @@ class Net_SFTP extends Net_SSH2 { return false; } - return $this->_stat($filename, NET_SFTP_STAT); + return $this->_identify_type($filename, NET_SFTP_STAT, NET_SFTP_LSTAT); } /** @@ -794,7 +794,7 @@ class Net_SFTP extends Net_SSH2 { return false; } - return $this->_stat($filename, NET_SFTP_LSTAT); + return $this->_identify_type($filename, NET_SFTP_LSTAT, NET_SFTP_STAT); } /** @@ -834,6 +834,33 @@ class Net_SFTP extends Net_SSH2 { return false; } + /** + * Attempt to identify the file type + * + * @param String $path + * @param Array $stat + * @param Array $lstat + * @return Integer + * @access private + */ + function _identify_type($path, $stat1, $stat2) + { + $stat1 = $this->_stat($path, $stat1); + $stat2 = $this->_stat($path, $stat2); + + if ($stat1 != $stat2) { + return array_merge($stat1, array('type' => NET_SFTP_TYPE_SYMLINK)); + } + + $pwd = $this->pwd; + $stat1['type'] = $this->chdir($path) ? + NET_SFTP_TYPE_DIRECTORY : + NET_SFTP_TYPE_REGULAR; + $this->pwd = $pwd; + + return $stat1; + } + /** * Returns the file size, in bytes, or false, on failure *