libssh2_sftp_seek64: flush packetlist and buffered data

When seeking to a new position, flush the packetlist and buffered data
to prevent already received or pending data to wrongly get used when
sftp-reading from the new offset within the file.
This commit is contained in:
liuzl
2011-08-26 13:47:35 +02:00
committed by Daniel Stenberg
parent 900c90ccbe
commit 8c0294db66

View File

@@ -1859,8 +1859,18 @@ libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *hnd,
LIBSSH2_API void
libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, libssh2_uint64_t offset)
{
if(handle)
if(handle) {
handle->u.file.offset = handle->u.file.offset_sent = offset;
/* discard all pending requests and currently read data */
sftp_packetlist_flush(handle);
/* free the left received buffered data */
if (handle->u.file.data_left) {
LIBSSH2_FREE(handle->sftp->channel->session, handle->u.file.data);
handle->u.file.data_left = handle->u.file.data_len = 0;
handle->u.file.data = NULL;
}
}
}
/* libssh2_sftp_seek