www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: Re: [PATCH] sftp: seek: Don't flush buffers if the requested offset is the same as current

Re: [PATCH] sftp: seek: Don't flush buffers if the requested offset is the same as current

From: Richard W.M. Jones <rjones_at_redhat.com>
Date: Tue, 26 Mar 2013 17:07:39 +0000

On Tue, Mar 26, 2013 at 04:58:03PM +0000, Richard W.M. Jones wrote:
> Nevertheless the change should be
> obviously correct by inspection, so I don't see what harm it would do.

I should add "obviously correct _if_ you use 'git show -w' to avoid
whitespace changes". The change looks like this:

----------------------------------------------------------------------
diff --git a/src/sftp.c b/src/sftp.c
index d0536dd..3760025 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -2132,7 +2132,11 @@ 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)
+ return;
+ if(handle->u.file.offset == offset && handle->u.file.offset_sent == offset)
+ return;
+
     handle->u.file.offset = handle->u.file.offset_sent = offset;
     /* discard all pending requests and currently read data */
     sftp_packetlist_flush(handle);
@@ -2147,7 +2151,6 @@ libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, libssh2_uint64_t offset)
     /* reset EOF to False */
     handle->u.file.eof = FALSE;
 }
-}
 
 /* libssh2_sftp_seek
  * Set the read/write pointer to an arbitrary position within the file
----------------------------------------------------------------------

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2013-03-26

the libssh2 team