wk, we, rk, index = hashutil.generate_dirnode_keys_from_readkey(rk)
return "DIR-REFRESH:%s" % idlib.b2a(index)
+ def get_child_at_path(self, path):
+ if not path:
+ return self
+ if isinstance(path, (str, unicode)):
+ path = path.split("/")
+ childname = path[0]
+ remaining_path = path[1:]
+ d = self.get(childname)
+ if remaining_path:
+ def _got(node):
+ return node.get_child_at_path(remaining_path)
+ d.addCallback(_got)
+ return d
+
class MutableDirectoryNode(ImmutableDirectoryNode):
implements(IDirectoryNode)
"""I return a Deferred that fires with a specific named child node,
either an IFileNode or an IDirectoryNode."""
+ def get_child_at_path(path):
+ """Transform a child path into an IDirectoryNode or IFileNode.
+
+ I perform a recursive series of 'get' operations to find the named
+ descendant node. I return a Deferred that fires with the node, or
+ errbacks with IndexError if the node could not be found.
+
+ The path can be either a single string (slash-separated) or a list of
+ path-name elements.
+ """
+
def set_uri(name, child_uri):
"""I add a child (by URI) at the specific name. I return a Deferred
that fires when the operation finishes.
d.addCallback(lambda res:
self.failIf(res["baz"].is_mutable()))
+ d.addCallback(lambda res: rootnode.get_child_at_path("bar/file2"))
+ def _got_file2(res):
+ self.failUnless(isinstance(res, dirnode.FileNode))
+ self.failUnlessEqual(res.uri, file2)
+ d.addCallback(_got_file2)
+
+ d.addCallback(lambda res: rootnode.get_child_at_path(["bar", "file2"]))
+ d.addCallback(_got_file2)
+
+ d.addCallback(lambda res: self.bar_node.get_child_at_path(["file2"]))
+ d.addCallback(_got_file2)
+
+ d.addCallback(lambda res: self.bar_node.get_child_at_path([]))
+ d.addCallback(lambda res: self.failUnlessIdentical(res, self.bar_node))
+
# test the manifest
d.addCallback(lambda res: self.rootnode.build_manifest())
def _check_manifest(manifest):