]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
IDirectoryNode: add has_child() method
authorBrian Warner <warner@allmydata.com>
Wed, 15 Aug 2007 20:22:01 +0000 (13:22 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 15 Aug 2007 20:22:01 +0000 (13:22 -0700)
src/allmydata/dirnode.py
src/allmydata/interfaces.py
src/allmydata/test/test_dirnode.py

index 621027cbb9db71915efcd5c21a0d4d9b972d4dc4..b3d6d8261d72483dbffc5e8bdf23a465b41f51f4 100644 (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)
index 771c230606ce4fa11e55342e558cacdcdc428523..b8369d471ff3e5680fab260277588fc84b7974dd 100644 (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."""
index cc64c4ef31d2af11171b6010fc86f0f448f1e250..47e1eb5d9c44eda595dfac52aad0ce26e3b7d814 100644 (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):