]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
dirnode deep-check: rearrange traversal approach, simplify code a bit
authorBrian Warner <warner@allmydata.com>
Thu, 17 Jul 2008 21:25:04 +0000 (14:25 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 17 Jul 2008 21:25:04 +0000 (14:25 -0700)
src/allmydata/dirnode.py

index d8d3e93b1a951a2237c37fbbe21308073b0d071c..31066b536ae936a276a09947ea28330f88b0dc05 100644 (file)
@@ -535,47 +535,43 @@ class NewDirectoryNode:
         return d
 
     def deep_check(self, verify=False, repair=False):
+        # shallow-check each object first, then traverse children
         results = DeepCheckResults()
         found = set()
-        found.add(self.get_verifier())
-
         limiter = ConcurrencyLimiter(10)
 
-        d = self._add_check_from_node(self, results, limiter, verify, repair)
-        d.addCallback(lambda res:
-                      self._add_deepcheck_from_dirnode(self,
-                                                       found, results, limiter,
-                                                       verify, repair))
+        d = self._add_deepcheck_from_node(self, results, found, limiter,
+                                          verify, repair)
         d.addCallback(lambda res: results)
         return d
 
-    def _add_check_from_node(self, node, results, limiter, verify, repair):
+    def _add_deepcheck_from_node(self, node, results, found, limiter,
+                                 verify, repair):
+        verifier = node.get_verifier()
+        if verifier in found:
+            # avoid loops
+            return None
+        found.add(verifier)
+
         d = limiter.add(node.check, verify, repair)
         d.addCallback(results.add_check)
-        return d
 
-    def _add_deepcheck_from_dirnode(self, node, found, results, limiter,
-                                    verify, repair):
-        d = limiter.add(node.list)
-        def _got_list(children):
-            dl = []
-            for name, (child, metadata) in children.iteritems():
-                verifier = child.get_verifier()
-                if verifier in found:
-                    # avoid loops
-                    continue
-                dl.append(self._add_check_from_node(child,
-                                                    results, limiter,
-                                                    verify, repair))
-                if IDirectoryNode.providedBy(child):
-                    dl.append(self._add_deepcheck_from_node(child, found,
-                                                            results, limiter,
-                                                            verify, repair))
-            if dl:
-                return defer.DeferredList(dl)
-        d.addCallback(_got_list)
+        if IDirectoryNode.providedBy(node):
+            d.addCallback(lambda res: node.list())
+            def _got_children(children):
+                dl = []
+                for name, (child, metadata) in children.iteritems():
+                    d2 = self._add_deepcheck_from_node(child,
+                                                       results, limiter,
+                                                       verify, repair)
+                    if d2:
+                        dl.append(d1)
+                if dl:
+                    return defer.DeferredList(dl)
+            d.addCallback(_got_children)
         return d
 
+
 class DeepStats:
     def __init__(self):
         self.stats = {}