1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-04 18:48:24 +01:00

Merge branch '3.0'

This commit is contained in:
terrafrost 2022-10-04 21:31:51 -05:00
commit b2ca37b990
2 changed files with 32 additions and 7 deletions

View File

@ -816,6 +816,12 @@ class SFTP extends SSH2
{
$files = $this->readlist($dir, false);
// If we get an int back, then that is an "unexpected" status.
// We do not have a file list, so return false.
if (is_int($files)) {
return false;
}
if (!$recursive || $files === false) {
return $files;
}
@ -846,6 +852,13 @@ class SFTP extends SSH2
public function rawlist(string $dir = '.', bool $recursive = false)
{
$files = $this->readlist($dir, true);
// If we get an int back, then that is an "unexpected" status.
// We do not have a file list, so return false.
if (is_int($files)) {
return false;
}
if (!$recursive || $files === false) {
return $files;
}
@ -909,8 +922,9 @@ class SFTP extends SSH2
break;
case SFTPPacketType::STATUS:
// presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
$this->logError($response);
return false;
list($status) = Strings::unpackSSH2('N', $response);
$this->logError($response, $status);
return $status;
default:
throw new UnexpectedValueException('Expected PacketType::HANDLE or PacketType::STATUS. '
. 'Got packet type: ' . $this->packet_type);
@ -963,7 +977,7 @@ class SFTP extends SSH2
[$status] = Strings::unpackSSH2('N', $response);
if ($status != StatusCode::EOF) {
$this->logError($response, $status);
return false;
return $status;
}
break 2;
default:
@ -1548,7 +1562,7 @@ class SFTP extends SSH2
$i = 0;
$entries = $this->readlist($path, true);
if ($entries === false) {
if ($entries === false || is_int($entries)) {
return $this->setstat($path, $attr, false);
}
@ -2310,9 +2324,14 @@ class SFTP extends SSH2
$i = 0;
$entries = $this->readlist($path, true);
// normally $entries would have at least . and .. but it might not if the directories
// permissions didn't allow reading
if (empty($entries)) {
// The folder does not exist at all, so we cannot delete it.
if ($entries === NET_SFTP_STATUS_NO_SUCH_FILE) {
return false;
}
// Normally $entries would have at least . and .. but it might not if the directories
// permissions didn't allow reading. If this happens then default to an empty list of files.
if ($entries === false || is_int($entries)) {
$entries = [];
}

View File

@ -639,6 +639,12 @@ class SFTPUserStoryTest extends PhpseclibFunctionalTestCase
'Failed asserting that stat on a deleted directory returns false'
);
$this->assertFalse(
$sftp->delete(self::$scratchDir),
'Failed asserting that non-existent directory could not ' .
'be deleted using recursive delete().'
);
return $sftp;
}