mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
IDirectoryNode: add has_child() method
This commit is contained in:
parent
244471dcc4
commit
42dcc3088e
@ -234,6 +234,16 @@ class ImmutableDirectoryNode:
|
|||||||
def _hash_name(self, name):
|
def _hash_name(self, name):
|
||||||
return hashutil.dir_name_hash(self._readkey, 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):
|
def get(self, name):
|
||||||
H_name = self._hash_name(name)
|
H_name = self._hash_name(name)
|
||||||
d = self._rref.callRemote("get", self._index, H_name)
|
d = self._rref.callRemote("get", self._index, H_name)
|
||||||
|
@ -352,6 +352,10 @@ class IDirectoryNode(Interface):
|
|||||||
"""I return a Deferred that fires with a dictionary mapping child
|
"""I return a Deferred that fires with a dictionary mapping child
|
||||||
name to an IFileNode or IDirectoryNode."""
|
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):
|
def get(name):
|
||||||
"""I return a Deferred that fires with a specific named child node,
|
"""I return a Deferred that fires with a specific named child node,
|
||||||
either an IFileNode or an IDirectoryNode."""
|
either an IFileNode or an IDirectoryNode."""
|
||||||
|
@ -378,6 +378,12 @@ class Test(unittest.TestCase):
|
|||||||
# root/bar-ro/file4 = file2
|
# root/bar-ro/file4 = file2
|
||||||
# root/bar-ro/baz/
|
# 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
|
# test the manifest
|
||||||
d.addCallback(lambda res: self.rootnode.build_manifest())
|
d.addCallback(lambda res: self.rootnode.build_manifest())
|
||||||
def _check_manifest2(manifest):
|
def _check_manifest2(manifest):
|
||||||
|
Loading…
Reference in New Issue
Block a user