mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-09 15:20:58 +00:00
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:
commit
302f4f894b
@ -1061,11 +1061,12 @@ class Net_SFTP extends Net_SSH2
|
|||||||
$dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $path));
|
$dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $path));
|
||||||
|
|
||||||
$temp = &$this->stat_cache;
|
$temp = &$this->stat_cache;
|
||||||
foreach ($dirs as $dir) {
|
$max = count($dirs) - 1;
|
||||||
|
foreach ($dirs as $i=>$dir) {
|
||||||
if (!isset($temp[$dir])) {
|
if (!isset($temp[$dir])) {
|
||||||
$temp[$dir] = array();
|
$temp[$dir] = array();
|
||||||
}
|
}
|
||||||
if ($dir == end($dirs)) {
|
if ($i === $max) {
|
||||||
$temp[$dir] = $value;
|
$temp[$dir] = $value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1085,8 +1086,9 @@ class Net_SFTP extends Net_SSH2
|
|||||||
$dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $path));
|
$dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $path));
|
||||||
|
|
||||||
$temp = &$this->stat_cache;
|
$temp = &$this->stat_cache;
|
||||||
foreach ($dirs as $dir) {
|
$max = count($dirs) - 1;
|
||||||
if ($dir == end($dirs)) {
|
foreach ($dirs as $i=>$dir) {
|
||||||
|
if ($i === $max) {
|
||||||
unset($temp[$dir]);
|
unset($temp[$dir]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -2206,7 +2208,7 @@ class Net_SFTP extends Net_SSH2
|
|||||||
$result = $this->_query_stat_cache($path);
|
$result = $this->_query_stat_cache($path);
|
||||||
|
|
||||||
if (isset($result)) {
|
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;
|
return $result !== false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
public function testChDirUpHome($sftp)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user