IDirectoryNode: add has_child() method

This commit is contained in:
Brian Warner 2007-08-15 13:22:01 -07:00
parent 244471dcc4
commit 42dcc3088e
3 changed files with 20 additions and 0 deletions

View File

@ -234,6 +234,16 @@ class ImmutableDirectoryNode:
def _hash_name(self, name):
return hashutil.dir_name_hash(self._readkey, name)
def has_child(self, name):
d = self.get(name)
def _good(res):
return True
def _err(f):
f.trap(KeyError)
return False
d.addCallbacks(_good, _err)
return d
def get(self, name):
H_name = self._hash_name(name)
d = self._rref.callRemote("get", self._index, H_name)

View File

@ -352,6 +352,10 @@ class IDirectoryNode(Interface):
"""I return a Deferred that fires with a dictionary mapping child
name to an IFileNode or IDirectoryNode."""
def has_child(name):
"""I return a Deferred that fires with a boolean, True if there
exists a child of the given name, False if not."""
def get(name):
"""I return a Deferred that fires with a specific named child node,
either an IFileNode or an IDirectoryNode."""

View File

@ -378,6 +378,12 @@ class Test(unittest.TestCase):
# root/bar-ro/file4 = file2
# root/bar-ro/baz/
# test has_child
d.addCallback(lambda res: rootnode.has_child("bar"))
d.addCallback(self.failUnlessEqual, True)
d.addCallback(lambda res: rootnode.has_child("missing"))
d.addCallback(self.failUnlessEqual, False)
# test the manifest
d.addCallback(lambda res: self.rootnode.build_manifest())
def _check_manifest2(manifest):