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); $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;
} }
@ -846,6 +852,13 @@ class SFTP extends SSH2
public function rawlist(string $dir = '.', bool $recursive = false) public function rawlist(string $dir = '.', bool $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;
} }
@ -909,8 +922,9 @@ class SFTP extends SSH2
break; break;
case SFTPPacketType::STATUS: case SFTPPacketType::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 PacketType::HANDLE or PacketType::STATUS. ' throw new UnexpectedValueException('Expected PacketType::HANDLE or PacketType::STATUS. '
. 'Got packet type: ' . $this->packet_type); . 'Got packet type: ' . $this->packet_type);
@ -963,7 +977,7 @@ class SFTP extends SSH2
[$status] = Strings::unpackSSH2('N', $response); [$status] = Strings::unpackSSH2('N', $response);
if ($status != StatusCode::EOF) { if ($status != StatusCode::EOF) {
$this->logError($response, $status); $this->logError($response, $status);
return false; return $status;
} }
break 2; break 2;
default: default:
@ -1548,7 +1562,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);
} }
@ -2310,9 +2324,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

@ -639,6 +639,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;
} }