From bdb992467ce0b97ff8a548269da6e8c044c52ceb Mon Sep 17 00:00:00 2001
From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Thu, 12 Feb 2009 16:31:32 -0700
Subject: [PATCH] immutable repairer: add an assertion that a certain value in
 this tricky function is always what I think it is

---
 src/allmydata/immutable/repairer.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/allmydata/immutable/repairer.py b/src/allmydata/immutable/repairer.py
index 92957d97..6f21da2e 100644
--- a/src/allmydata/immutable/repairer.py
+++ b/src/allmydata/immutable/repairer.py
@@ -2,7 +2,7 @@ from zope.interface import implements
 from twisted.internet import defer
 from allmydata import storage
 from allmydata.util import log, observer
-from allmydata.util.assertutil import precondition
+from allmydata.util.assertutil import precondition, _assert
 from allmydata.uri import CHKFileVerifierURI
 from allmydata.interfaces import IEncryptedUploadable, IDownloadTarget
 from twisted.internet.interfaces import IConsumer
@@ -152,6 +152,8 @@ class DownUpConnector(log.PrefixingLogMixin):
                     extra = ressize - nrl
                     self.bufs.appendleft(nextbuf[:-extra])
                     res[-1] = nextbuf[:-extra]
+            assert _assert(sum(len(x) for x in res) <= nrl, [len(x) for x in res], nrl)
+            assert _assert(sum(len(x) for x in res) == nrl or self._closed_to_pusher, [len(x) for x in res], nrl)
             self.bufsiz -= nrl
             if self.bufsiz < self.buflim and self.producer:
                 self.producer.resumeProducing()
-- 
2.45.2