summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2006-04-20 00:26:27 -0700
committerRobey Pointer <robey@lag.net>2006-04-20 00:26:27 -0700
commitabb7f1f1ba4276274b4c131355508b2f4e90f906 (patch)
treecd6bbdeea9ed4aae79dfddc5ab0a81e211a1677d
parentd965f00563ef23dc3b105c3d1272075ec18c01af (diff)
[project @ robey@lag.net-20060420072627-958cad5e36cb8ecc]
fix a bug where prefetch() at EOF would throw an exception, and add a unit test
-rw-r--r--paramiko/sftp_file.py10
-rwxr-xr-xtests/test_sftp.py17
2 files changed, 23 insertions, 4 deletions
diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py
index e30cd38b..17f999e7 100644
--- a/paramiko/sftp_file.py
+++ b/paramiko/sftp_file.py
@@ -93,7 +93,7 @@ class SFTPFile (BufferedFile):
if self._prefetch_done:
return None
self.sftp._read_response()
- self._check_exception()
+ self._check_exception()
k = self._prefetch_data.keys()
if len(k) == 0:
self._prefetching = False
@@ -362,7 +362,8 @@ class SFTPFile (BufferedFile):
chunk = min(self.MAX_REQUEST_SIZE, size - n)
chunks.append((n, chunk))
n += chunk
- self._start_prefetch(chunks)
+ if len(chunks) > 0:
+ self._start_prefetch(chunks)
def readv(self, chunks):
"""
@@ -382,7 +383,8 @@ class SFTPFile (BufferedFile):
# put the offsets in order, since we depend on that for determining
# when the reads have finished.
self.sftp._log(DEBUG, 'readv(%s, %r)' % (util.hexify(self.handle), chunks))
- ordered_chunks = chunks[:]
+ # FIXME: if prefetch() was already called (not readv), don't prefetch.
+ ordered_chunks = list(chunks)
ordered_chunks.sort(lambda x, y: cmp(x[0], y[0]))
self._start_prefetch(ordered_chunks)
# now we can just devolve to a bunch of read()s :)
@@ -407,7 +409,7 @@ class SFTPFile (BufferedFile):
self._prefetch_done = False
self._prefetch_so_far = chunks[0][0]
self._prefetch_data = {}
- self._prefetch_reads.extend(chunks[:])
+ self._prefetch_reads.extend(chunks)
t = threading.Thread(target=self._prefetch_thread, args=(chunks,))
t.setDaemon(True)
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index 6172a0dc..3bc11e3e 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -622,3 +622,20 @@ class SFTPTest (unittest.TestCase):
self.fail('exception ' + e)
sftp.unlink(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65')
+ def test_L_bad_readv(self):
+ """
+ verify that readv at the end of the file doesn't essplode.
+ """
+ f = sftp.open(FOLDER + '/zero', 'w')
+ f.close()
+ try:
+ f = sftp.open(FOLDER + '/zero', 'r')
+ data = f.readv([(0, 12)])
+ f.close()
+
+ f = sftp.open(FOLDER + '/zero', 'r')
+ f.prefetch()
+ data = f.read(100)
+ f.close()
+ finally:
+ sftp.unlink(FOLDER + '/zero')