SFTP: add a comment about a subtle interaction between OverwriteableFileConsumer and GeneralSFTPFile, and test the case it is commenting on.

This commit is contained in:
david-sarah 2011-09-03 15:23:04 -07:00
parent 01b5124d0a
commit 1b7b3bd0d4
2 changed files with 9 additions and 0 deletions

View File

@ -461,6 +461,12 @@ class OverwriteableFileConsumer(PrefixingLogMixin):
The caller must perform no more overwrites until the Deferred has fired."""
if noisy: self.log(".read(%r, %r), current_size = %r" % (offset, length, self.current_size), level=NOISY)
# Note that the overwrite method is synchronous. When a write request is processed
# (e.g. a writeChunk request on the async queue of GeneralSFTPFile), overwrite will
# be called and will update self.current_size if necessary before returning. Therefore,
# self.current_size will be up-to-date for a subsequent call to this read method, and
# so it is correct to do the check for a read past the end-of-file here.
if offset >= self.current_size:
def _eof(): raise EOFError("read past end of file")
return defer.execute(_eof)

View File

@ -913,6 +913,9 @@ class Handler(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, unittest.TestCas
self.handler.openFile("small", sftp.FXF_READ | sftp.FXF_WRITE, {}))
def _read_write(rwf):
d2 = rwf.writeChunk(8, "0123")
# test immediate read starting after the old end-of-file
d2.addCallback(lambda ign: rwf.readChunk(11, 1))
d2.addCallback(lambda data: self.failUnlessReallyEqual(data, "3"))
d2.addCallback(lambda ign: rwf.readChunk(0, 100))
d2.addCallback(lambda data: self.failUnlessReallyEqual(data, "012345670123"))
d2.addCallback(lambda ign: rwf.close())