Merge pull request #409 from terrafrost/stat-cache-fix

SFTP: add unit test for stat cache fix

* terrafrost/stat-cache-fix:
  SFTP: stat cache fixes
  SFTP: return $sftp object in new unit test method
  SFTP: add unit test for stat cache fix
This commit is contained in:
Andreas Fischer 2014-07-20 21:41:50 +02:00
commit 302f4f894b
2 changed files with 24 additions and 6 deletions

View File

@ -1061,11 +1061,12 @@ class Net_SFTP extends Net_SSH2
$dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $path));
$temp = &$this->stat_cache;
foreach ($dirs as $dir) {
$max = count($dirs) - 1;
foreach ($dirs as $i=>$dir) {
if (!isset($temp[$dir])) {
$temp[$dir] = array();
}
if ($dir == end($dirs)) {
if ($i === $max) {
$temp[$dir] = $value;
break;
}
@ -1085,8 +1086,9 @@ class Net_SFTP extends Net_SSH2
$dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $path));
$temp = &$this->stat_cache;
foreach ($dirs as $dir) {
if ($dir == end($dirs)) {
$max = count($dirs) - 1;
foreach ($dirs as $i=>$dir) {
if ($i === $max) {
unset($temp[$dir]);
return true;
}
@ -2206,7 +2208,7 @@ class Net_SFTP extends Net_SSH2
$result = $this->_query_stat_cache($path);
if (isset($result)) {
// return true if $result is an array or if it's int(1)
// return true if $result is an array or if it's an stdClass object
return $result !== false;
}
}

View File

@ -342,7 +342,23 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
}
/**
* @depends testSortOrder
* on older versions this would result in a fatal error
* @depends testReadlink
* @group github402
*/
public function testStatcacheFix($sftp)
{
$sftp->mkdir('testdir');
$sftp->chdir('testdir');
$sftp->touch('testdir');
$sftp->chdir('..');
$sftp->delete('testdir', true);
return $sftp;
}
/**
* @depends testStatcacheFix
*/
public function testChDirUpHome($sftp)
{