]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
add RIMutableDirectoryNode.get, to get a specific child file or directory
authorBrian Warner <warner@lothar.com>
Mon, 4 Dec 2006 11:03:29 +0000 (04:03 -0700)
committerBrian Warner <warner@lothar.com>
Mon, 4 Dec 2006 11:03:29 +0000 (04:03 -0700)
allmydata/filetable.py
allmydata/interfaces.py
allmydata/test/test_filetable.py

index bacae6803b969157236d50a862966d920da390f0..e93413c1717cd03f4047d5f0c7c2acf6af49d21a 100644 (file)
@@ -27,14 +27,6 @@ class MutableDirectoryNode(Referenceable):
         if name == "." or name == ".." or "/" in name:
             raise DeadDirectoryNodeError("bad filename component")
 
-    # this is private
-    def get_child(self, name):
-        self.validate_name(name)
-        absname = os.path.join(self._basedir, name)
-        if os.path.isdir(absname):
-            return self.make_subnode(absname)
-        raise DeadDirectoryNodeError("no such directory")
-
     # these are the public methods, available to anyone who holds a reference
 
     def list(self):
@@ -55,6 +47,21 @@ class MutableDirectoryNode(Referenceable):
         return results
     remote_list = list
 
+    def get(self, name):
+        self.validate_name(name)
+        absname = os.path.join(self._basedir, name)
+        if os.path.isdir(absname):
+            return self.make_subnode(absname)
+        elif os.path.isfile(absname):
+            f = open(absname, "rb")
+            data = f.read()
+            f.close()
+            return data
+        else:
+            raise BadFileError("there is nothing named '%s' in this directory"
+                               % name)
+    remote_get = get
+
     def add_directory(self, name):
         self.validate_name(name)
         absname = os.path.join(self._basedir, name)
index f7e86b76a840f053150f6d81383ed1eaef7d1496..672bd9084cb98ff63a0afbfaaebd15bef19e956f 100644 (file)
@@ -55,6 +55,9 @@ class RIMutableDirectoryNode(RemoteInterface):
                        maxLength=100,
                        )
 
+    def get(name=str):
+        return (RIMutableDirectoryNode_, Verifierid)
+
     def add_directory(name=str):
         return RIMutableDirectoryNode_
 
index 060d0cc7b37fdb5f017cb83e59482356eed9c49e..f72a9d31bbad44ef39fd49b35e76a99c59c97cc5 100644 (file)
@@ -19,9 +19,15 @@ class FileTable(unittest.TestCase):
         self.failUnlessRaises(BadFileError, root.remove, "two")
         self.failUnlessRaises(BadFileError, root.remove, "three")
 
+        self.failUnlessEqual(root.get("one"), "vid-one")
+        self.failUnlessRaises(BadFileError, root.get, "missing")
+
         # now play with directories
         subdir1 = root.add_directory("subdir1")
         self.failUnless(isinstance(subdir1, MutableDirectoryNode))
+        subdir1a = root.get("subdir1")
+        self.failUnless(isinstance(subdir1a, MutableDirectoryNode))
+        self.failUnlessEqual(subdir1a._basedir, subdir1._basedir)
         entries = root.list()
         self.failUnlessEqual(len(entries), 2)
         one_index = entries.index( ("one", "vid-one") )