From 6fa41e738b4036efaf128e2b6a9ff284d5c4b0d6 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 4 Nov 2008 15:29:19 -0700 Subject: [PATCH] immutable: tolerate filenode.read() with a size= that's too big, rather than hanging --- src/allmydata/immutable/filenode.py | 2 +- src/allmydata/test/test_system.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/allmydata/immutable/filenode.py b/src/allmydata/immutable/filenode.py index 33395ef9..fbc00d86 100644 --- a/src/allmydata/immutable/filenode.py +++ b/src/allmydata/immutable/filenode.py @@ -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 diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 5a2fff15..618d4af7 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -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) -- 2.45.2