[Checkins] SVN: zc.zodbdgc/branches/dev/src/zc/zodbdgc/__init__.py Change a recursive copying of bad oids to good to be iterative (with

Jim Fulton jim at zope.com
Mon May 18 09:39:56 EDT 2009


Log message for revision 100067:
  Change a recursive copying of bad oids to good to be iterative (with
  an application-maintained stack) to avoid exceeding the python maximum
  recursion depth.
  

Changed:
  U   zc.zodbdgc/branches/dev/src/zc/zodbdgc/__init__.py

-=-
Modified: zc.zodbdgc/branches/dev/src/zc/zodbdgc/__init__.py
===================================================================
--- zc.zodbdgc/branches/dev/src/zc/zodbdgc/__init__.py	2009-05-18 09:34:41 UTC (rev 100066)
+++ zc.zodbdgc/branches/dev/src/zc/zodbdgc/__init__.py	2009-05-18 13:39:56 UTC (rev 100067)
@@ -152,26 +152,30 @@
     return os.path.join(baddir, name, base64.urlsafe_b64encode(oid))
 
 def bad_to_good(baddir, bad, good, name, oid):
-    bad.remove(name, oid)
 
-    path = bad_path(baddir, name, oid)
-    if not os.path.exists(path):
-        return
+    to_do = [(name, oid)]
+    while to_do:
+        name, oid = to_do.pop()
+        bad.remove(name, oid)
 
-    f = open(path , 'rb')
-    while 1:
-        try:
-            refs = marshal.load(f)
-        except EOFError:
-            break
+        path = bad_path(baddir, name, oid)
+        if not os.path.exists(path):
+            return
 
-        for ref in refs:
-            if good.insert(*ref) and bad.has(*ref):
-                bad_to_good(baddir, bad, good, *ref)
+        f = open(path , 'rb')
+        while 1:
+            try:
+                refs = marshal.load(f)
+            except EOFError:
+                break
 
-    f.close()
-    os.remove(path)
+            for ref in refs:
+                if good.insert(*ref) and bad.has(*ref):
+                    to_do.append(ref)
 
+        f.close()
+        os.remove(path)
+
 def getrefs(p, rname):
     refs = []
     u = cPickle.Unpickler(cStringIO.StringIO(p))



More information about the Checkins mailing list