[Zope-Checkins] CVS: ZODB3/Tools - repozo.py:1.1.2.11

Tim Peters tim.one at comcast.net
Sun Aug 17 00:57:51 EDT 2003


Update of /cvs-repository/ZODB3/Tools
In directory cvs.zope.org:/tmp/cvs-serv21212/Tools

Modified Files:
      Tag: ZODB3-3_1-branch
	repozo.py 
Log Message:
dofile():  Don't blow up in earlier Pythons if more than 2GB needs to be
read.  Documented was this does.  Reworked the logic so it's more obvious
to my eyes.


=== ZODB3/Tools/repozo.py 1.1.2.10 => 1.1.2.11 ===
--- ZODB3/Tools/repozo.py:1.1.2.10	Sat Aug 16 23:28:31 2003
+++ ZODB3/Tools/repozo.py	Sat Aug 16 23:57:46 2003
@@ -187,20 +187,26 @@
 
 
 
-# Do something with a run of bytes from a file
+# Read bytes (no more than n, or to EOF if n is None) in chunks from the
+# current position in file fp.  Pass each chunk as an argument to func().
+# Return the total number of bytes read == the total number of bytes
+# passed in all to func().  Leaves the file position just after the
+# last byte read.
 def dofile(func, fp, n=None):
-    bytesread = 0
-    stop = False
-    chunklen = READCHUNK
-    while not stop:
-        if n is not None and chunklen + bytesread > n:
-            chunklen = n - bytesread
-            stop = True
-        data = fp.read(chunklen)
+    bytesread = 0L
+    while n is None or n > 0:
+        if n is None:
+            todo = READCHUNK
+        else:
+            todo = min(READCHUNK, n)
+        data = fp.read(todo)
         if not data:
             break
         func(data)
-        bytesread += len(data)
+        nread = len(data)
+        bytesread += nread
+        if n is not None:
+            n -= nread
     return bytesread
 
 
@@ -416,7 +422,7 @@
         if sum == srcsum:
             if srcsz == endpos:
                 log('No changes, nothing to do')
-                return    
+                return
             log('doing incremental, starting at: %s', endpos)
             do_incremental_backup(options, endpos, repofiles)
             return




More information about the Zope-Checkins mailing list