Merge branch '2.0' into 3.0

This commit is contained in:
terrafrost 2022-10-04 21:02:49 -05:00
commit a10a3b8e5b
2 changed files with 32 additions and 7 deletions

View File

@ -1003,6 +1003,12 @@ class SFTP extends SSH2
{ {
$files = $this->readlist($dir, false); $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) { if (!$recursive || $files === false) {
return $files; return $files;
} }
@ -1035,6 +1041,13 @@ class SFTP extends SSH2
public function rawlist($dir = '.', $recursive = false) public function rawlist($dir = '.', $recursive = false)
{ {
$files = $this->readlist($dir, true); $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) { if (!$recursive || $files === false) {
return $files; return $files;
} }
@ -1100,8 +1113,9 @@ class SFTP extends SSH2
break; break;
case NET_SFTP_STATUS: case NET_SFTP_STATUS:
// presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
$this->logError($response); list($status) = Strings::unpackSSH2('N', $response);
return false; $this->logError($response, $status);
return $status;
default: default:
throw new \UnexpectedValueException('Expected NET_SFTP_HANDLE or NET_SFTP_STATUS. ' throw new \UnexpectedValueException('Expected NET_SFTP_HANDLE or NET_SFTP_STATUS. '
. 'Got packet type: ' . $this->packet_type); . 'Got packet type: ' . $this->packet_type);
@ -1154,7 +1168,7 @@ class SFTP extends SSH2
list($status) = Strings::unpackSSH2('N', $response); list($status) = Strings::unpackSSH2('N', $response);
if ($status != NET_SFTP_STATUS_EOF) { if ($status != NET_SFTP_STATUS_EOF) {
$this->logError($response, $status); $this->logError($response, $status);
return false; return $status;
} }
break 2; break 2;
default: default:
@ -1782,7 +1796,7 @@ class SFTP extends SSH2
$i = 0; $i = 0;
$entries = $this->readlist($path, true); $entries = $this->readlist($path, true);
if ($entries === false) { if ($entries === false || is_int($entries)) {
return $this->setstat($path, $attr, false); return $this->setstat($path, $attr, false);
} }
@ -2581,9 +2595,14 @@ class SFTP extends SSH2
$i = 0; $i = 0;
$entries = $this->readlist($path, true); $entries = $this->readlist($path, true);
// normally $entries would have at least . and .. but it might not if the directories // The folder does not exist at all, so we cannot delete it.
// permissions didn't allow reading if ($entries === NET_SFTP_STATUS_NO_SUCH_FILE) {
if (empty($entries)) { 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 = []; $entries = [];
} }

View File

@ -636,6 +636,12 @@ class SFTPUserStoryTest extends PhpseclibFunctionalTestCase
'Failed asserting that stat on a deleted directory returns false' '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; return $sftp;
} }