Commit 73c431ec authored by Albert Flügel's avatar Albert Flügel Committed by Andreas Schneider

sftp: Fix short read receiving files.

This corrupted some files during transfer.
Reviewed-by: default avatarAndreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 8581c327)
parent 7e3a10d5
......@@ -2161,20 +2161,22 @@ int sftpProtocol::GetRequest::readChunks(QByteArray &data) {
totalRead += bytesread;
if (bytesread < request.expectedLength) {
int rc;
// If less data is read than expected - requeue the request
data.resize(data.size() - (request.expectedLength - bytesread));
// Save current file offset
uint64_t oldOffset = mFile->offset;
mFile->offset = request.startOffset + bytesread;
// Modify current request
request.expectedLength = request.expectedLength - bytesread;
request.startOffset = mFile->offset;
request.id = sftp_async_read_begin(mFile, request.expectedLength);
request.expectedLength -= bytesread;
request.startOffset += bytesread;
// Restore the file offset
mFile->offset = oldOffset;
rc = sftp_seek64(mFile, request.startOffset);
if (rc < 0) {
// Failed to continue reading
return -1;
}
request.id = sftp_async_read_begin(mFile, request.expectedLength);
if (request.id < 0) {
// Failed to dispatch rerequest
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment