mirror of
https://github.com/danog/phpseclib.git
synced 2024-11-26 20:35:21 +01:00
Merge branch '1.0' into 2.0
* 1.0: SFTP: stat cache updates
This commit is contained in:
commit
4b5cc0c286
@ -862,7 +862,7 @@ class SFTP extends SSH2
|
||||
} else {
|
||||
$temp = $dir . '/' . $shortname;
|
||||
}
|
||||
$this->_update_stat_cache($temp, (object) array('stat' => $attributes));
|
||||
$this->_update_stat_cache($temp, (object) array('lstat' => $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,12 @@ class SFTP extends SSH2
|
||||
$temp = &$this->stat_cache;
|
||||
$max = count($dirs) - 1;
|
||||
foreach ($dirs as $i=>$dir) {
|
||||
// if $temp is an object that means one of two things.
|
||||
// 1. a file was deleted and changed to a directory behind phpseclib's back
|
||||
// 2. it's a symlink. when lstat is done it's unclear what it's a symlink to
|
||||
if (is_object($temp)) {
|
||||
$temp = array();
|
||||
}
|
||||
if (!isset($temp[$dir])) {
|
||||
$temp[$dir] = array();
|
||||
}
|
||||
@ -1122,7 +1128,7 @@ class SFTP extends SSH2
|
||||
|
||||
if ($this->use_stat_cache) {
|
||||
$result = $this->_query_stat_cache($filename);
|
||||
if (is_array($result) && isset($result['.'])) {
|
||||
if (is_array($result) && isset($result['.']) && isset($result['.']->stat)) {
|
||||
return $result['.']->stat;
|
||||
}
|
||||
if (is_object($result) && isset($result->stat)) {
|
||||
|
@ -596,5 +596,52 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
|
||||
$sftp->stat(self::$scratchDir),
|
||||
'Failed asserting that stat on a deleted directory returns false'
|
||||
);
|
||||
|
||||
return $sftp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDeleteEmptyDir
|
||||
* @group github735
|
||||
*/
|
||||
public function testStatVsLstat($sftp)
|
||||
{
|
||||
$this->assertTrue($sftp->mkdir(self::$scratchDir));
|
||||
$this->assertTrue($sftp->chdir(self::$scratchDir));
|
||||
$this->assertTrue($sftp->put('text.txt', 'zzzzz'));
|
||||
$this->assertTrue($sftp->symlink('text.txt', 'link.txt'));
|
||||
$this->assertTrue($sftp->mkdir('subdir'));
|
||||
$this->assertTrue($sftp->symlink('subdir', 'linkdir'));
|
||||
|
||||
$sftp->clearStatCache();
|
||||
|
||||
// pre-populate the stat cache
|
||||
$sftp->nlist();
|
||||
|
||||
$stat = $sftp->stat('link.txt');
|
||||
$this->assertSame($stat['type'], NET_SFTP_TYPE_REGULAR);
|
||||
$stat = $sftp->lstat('link.txt');
|
||||
$this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK);
|
||||
|
||||
$stat = $sftp->stat('linkdir');
|
||||
$this->assertSame($stat['type'], NET_SFTP_TYPE_DIRECTORY);
|
||||
$stat = $sftp->lstat('link.txt');
|
||||
$this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK);
|
||||
|
||||
$sftp->disableStatCache();
|
||||
|
||||
$sftp->nlist();
|
||||
|
||||
$stat = $sftp->stat('link.txt');
|
||||
$this->assertSame($stat['type'], NET_SFTP_TYPE_REGULAR);
|
||||
$stat = $sftp->lstat('link.txt');
|
||||
$this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK);
|
||||
|
||||
$stat = $sftp->stat('linkdir');
|
||||
$this->assertSame($stat['type'], NET_SFTP_TYPE_DIRECTORY);
|
||||
$stat = $sftp->lstat('link.txt');
|
||||
$this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK);
|
||||
|
||||
$sftp->enableStatCache();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user