]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
immutable: tolerate filenode.read() with a size= that's too big, rather than hanging
authorBrian Warner <warner@allmydata.com>
Tue, 4 Nov 2008 22:29:19 +0000 (15:29 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 4 Nov 2008 22:29:19 +0000 (15:29 -0700)
src/allmydata/immutable/filenode.py
src/allmydata/test/test_system.py

index 33395ef99c6b3c769082aad5cba6097c7feeb28b..fbc00d866fe6b992e39d4cf8f4fd3ec9dd6b11a6 100644 (file)
@@ -221,7 +221,7 @@ class FileNode(_ImmutableFileNodeBase):
     def read(self, consumer, offset=0, size=None):
         if size is None:
             size = self.get_size() - offset
-
+        size = min(size, self.get_size() - offset)
 
         if offset == 0 and size == self.get_size():
             # don't use the cache, just do a normal streaming download
index 5a2fff15843cfb73881e850a2a7f98512aac1dd6..618d4af7ecd2e603f2eaef7f23ab9d97bed4ff01 100644 (file)
@@ -202,6 +202,11 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
             def _read_tail_done(mc):
                 self.failUnlessEqual("".join(mc.chunks), DATA[2:])
             d.addCallback(_read_tail_done)
+            d.addCallback(lambda ign:
+                          n.read(MemoryConsumer(), size=len(DATA)+1000))
+            def _read_too_much(mc):
+                self.failUnlessEqual("".join(mc.chunks), DATA)
+            d.addCallback(_read_too_much)
 
             return d
         d.addCallback(_test_read)