From acf3180facd2a30ed744797a57f44777a5aff449 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 17 Jul 2008 14:25:04 -0700 Subject: [PATCH] dirnode deep-check: rearrange traversal approach, simplify code a bit --- src/allmydata/dirnode.py | 54 +++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/allmydata/dirnode.py b/src/allmydata/dirnode.py index d8d3e93b..31066b53 100644 --- a/src/allmydata/dirnode.py +++ b/src/allmydata/dirnode.py @@ -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 = {} -- 2.45.2