From: Brian Warner Date: Wed, 15 Aug 2007 20:22:01 +0000 (-0700) Subject: IDirectoryNode: add has_child() method X-Git-Url: https://git.rkrishnan.org/simplejson/%3C?a=commitdiff_plain;h=42dcc3088e2ecc5c35148a156407659d219567dd;p=tahoe-lafs%2Ftahoe-lafs.git IDirectoryNode: add has_child() method --- diff --git a/src/allmydata/dirnode.py b/src/allmydata/dirnode.py index 621027cb..b3d6d826 100644 --- a/src/allmydata/dirnode.py +++ b/src/allmydata/dirnode.py @@ -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) diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index 771c2306..b8369d47 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -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.""" diff --git a/src/allmydata/test/test_dirnode.py b/src/allmydata/test/test_dirnode.py index cc64c4ef..47e1eb5d 100644 --- a/src/allmydata/test/test_dirnode.py +++ b/src/allmydata/test/test_dirnode.py @@ -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):