Merge branch '2.0'

* 2.0:
  Unit/X509/CSR: looks like a line got overwritten..
  SFTP: stat cache updates
This commit is contained in:
Andreas Fischer 2015-06-22 01:19:33 +02:00
commit d098568e4f
2 changed files with 91 additions and 18 deletions

View File

@ -862,7 +862,7 @@ class SFTP extends SSH2
} else {
$temp = $dir . '/' . $shortname;
}
$this->_update_stat_cache($temp, (object) $attributes);
$this->_update_stat_cache($temp, (object) array('stat' => $attributes));
}
// SFTPv6 has an optional boolean end-of-list field, but we'll ignore that, since the
// final SSH_FXP_STATUS packet should tell us that, already.
@ -1033,6 +1033,14 @@ class SFTP extends SSH2
$temp[$dir] = array();
}
if ($i === $max) {
if (is_object($temp[$dir])) {
if (!isset($value->stat) && isset($temp[$dir]->stat)) {
$value->stat = $temp[$dir]->stat;
}
if (!isset($value->lstat) && isset($temp[$dir]->lstat)) {
$value->lstat = $temp[$dir]->lstat;
}
}
$temp[$dir] = $value;
break;
}
@ -1111,10 +1119,10 @@ class SFTP extends SSH2
if ($this->use_stat_cache) {
$result = $this->_query_stat_cache($filename);
if (is_array($result) && isset($result['.'])) {
return (array) $result['.'];
return $result['.']->stat;
}
if (is_object($result)) {
return (array) $result;
if (is_object($result) && isset($result->stat)) {
return $result->stat;
}
}
@ -1127,7 +1135,7 @@ class SFTP extends SSH2
if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) {
$filename.= '/.';
}
$this->_update_stat_cache($filename, (object) $stat);
$this->_update_stat_cache($filename, (object) array('stat' => $stat));
return $stat;
}
@ -1140,7 +1148,7 @@ class SFTP extends SSH2
if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) {
$filename.= '/.';
}
$this->_update_stat_cache($filename, (object) $stat);
$this->_update_stat_cache($filename, (object) array('stat' => $stat));
return $stat;
}
@ -1168,10 +1176,10 @@ class SFTP extends SSH2
if ($this->use_stat_cache) {
$result = $this->_query_stat_cache($filename);
if (is_array($result) && isset($result['.'])) {
return (array) $result['.'];
return $result['.']->lstat;
}
if (is_object($result)) {
return (array) $result;
if (is_object($result) && isset($result->lstat)) {
return $result->lstat;
}
}
@ -1184,7 +1192,7 @@ class SFTP extends SSH2
if ($lstat['type'] == NET_SFTP_TYPE_DIRECTORY) {
$filename.= '/.';
}
$this->_update_stat_cache($filename, (object) $lstat);
$this->_update_stat_cache($filename, (object) array('lstat' => $lstat));
return $lstat;
}
@ -1192,7 +1200,7 @@ class SFTP extends SSH2
if ($lstat != $stat) {
$lstat = array_merge($lstat, array('type' => NET_SFTP_TYPE_SYMLINK));
$this->_update_stat_cache($filename, (object) $lstat);
$this->_update_stat_cache($filename, (object) array('lstat' => $lstat));
return $stat;
}
@ -1205,7 +1213,7 @@ class SFTP extends SSH2
if ($lstat['type'] == NET_SFTP_TYPE_DIRECTORY) {
$filename.= '/.';
}
$this->_update_stat_cache($filename, (object) $lstat);
$this->_update_stat_cache($filename, (object) array('lstat' => $lstat));
return $lstat;
}
@ -2262,7 +2270,7 @@ class SFTP extends SSH2
*/
function is_link($path)
{
$result = $this->_get_stat_cache_prop($path, 'type');
$result = $this->_get_lstat_cache_prop($path, 'type');
if ($result === false) {
return false;
}
@ -2377,18 +2385,48 @@ class SFTP extends SSH2
* @access private
*/
function _get_stat_cache_prop($path, $prop)
{
return $this->_get_xstat_cache_prop($path, $prop, 'stat');
}
/**
* Return an lstat properity
*
* Uses cache if appropriate.
*
* @param String $path
* @param String $prop
* @return Mixed
* @access private
*/
function _get_lstat_cache_prop($path, $prop)
{
return $this->_get_xstat_cache_prop($path, $prop, 'lstat');
}
/**
* Return a stat or lstat properity
*
* Uses cache if appropriate.
*
* @param String $path
* @param String $prop
* @return Mixed
* @access private
*/
function _get_xstat_cache_prop($path, $prop, $type)
{
if ($this->use_stat_cache) {
$path = $this->_realpath($path);
$result = $this->_query_stat_cache($path);
if (is_object($result) && isset($result->$prop)) {
return $result->$prop;
if (is_object($result) && isset($result->$type)) {
return $result->{$type}[$prop];
}
}
$result = $this->stat($path);
$result = $this->$type($path);
if ($result === false || !isset($result[$prop])) {
return false;

View File

@ -160,7 +160,6 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
return $sftp;
}
static function callback($length)
{
$r = substr(self::$buffer, 0, $length);
@ -174,7 +173,7 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
*/
public function testPutSizeGetFileCallback($sftp)
{
self::$buffer = self::$exampleData;
self::$buffer = self::$exampleData;
$this->assertTrue(
$sftp->put('file1.txt', array(__CLASS__, 'callback'), $sftp::SOURCE_CALLBACK),
'Failed asserting that example data could be successfully put().'
@ -384,6 +383,42 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
/**
* @depends testSymlink
*/
public function testStatLstatCache($sftp)
{
$stat = $sftp->stat('symlink');
$lstat = $sftp->lstat('symlink');
$this->assertNotEquals(
$stat, $lstat,
'Failed asserting that stat and lstat returned different output for a symlink'
);
return $sftp;
}
/**
* @depends testStatLstatCache
*/
public function testLinkFile($sftp)
{
$this->assertTrue(
$sftp->is_link('symlink'),
'Failed asserting that symlink is a link'
);
$this->assertTrue(
$sftp->is_file('symlink'),
'Failed asserting that symlink is a file'
);
$this->assertFalse(
$sftp->is_dir('symlink'),
'Failed asserting that symlink is not a directory'
);
return $sftp;
}
/**
* @depends testLinkFile
*/
public function testReadlink($sftp)
{
$this->assertInternalType('string', $sftp->readlink('symlink'),