]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
webish: implement 'PUT /uri?t=mkdir' (to create anonymous dirnodes)
authorBrian Warner <warner@allmydata.com>
Thu, 6 Sep 2007 00:23:06 +0000 (17:23 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 6 Sep 2007 00:23:06 +0000 (17:23 -0700)
src/allmydata/interfaces.py
src/allmydata/test/test_web.py
src/allmydata/vdrive.py

index e2edc242fa130bcb7b1395ab5327804ae7727378..e5b08aa50f4ba70dfb8571356ab353bada8139d8 100644 (file)
@@ -1015,6 +1015,11 @@ class IVirtualDrive(Interface):
         This returns a Deferred that will fire with an instance that provides
         either IDirectoryNode or IFileNode, as appropriate."""
 
+    def create_directory():
+        """Return a new IDirectoryNode that is empty and not linked by
+        anything."""
+
+
 class NotCapableError(Exception):
     """You have tried to write to a read-only node."""
 
index c691a682c80bb1a04596856a472621bdda84e638..a4f5c579087598beb74e85abc7920e6e329ba7fe 100644 (file)
@@ -142,8 +142,9 @@ class MyVirtualDrive(service.Service):
     name = "vdrive"
     public_root = None
     private_root = None
-    def __init__(self, nodes):
+    def __init__(self, nodes, files):
         self._my_nodes = nodes
+        self._my_files = files
     def have_public_root(self):
         return bool(self.public_root)
     def have_private_root(self):
@@ -158,6 +159,12 @@ class MyVirtualDrive(service.Service):
             return self._my_nodes[uri]
         return defer.maybeDeferred(_try)
 
+    def create_directory(self):
+        # the dirnode adds itself to self.nodes
+        dirnode = MyDirectoryNode(self._my_nodes, self._my_files, self.parent)
+        return defer.succeed(dirnode)
+
+
 class WebMixin(object):
     def setUp(self):
         self.s = MyClient()
@@ -171,7 +178,7 @@ class WebMixin(object):
         self.nodes = {} # maps URI to node
         self.files = {} # maps file URI to contents
 
-        v = MyVirtualDrive(self.nodes)
+        v = MyVirtualDrive(self.nodes, self.files)
         v.setServiceParent(self.s)
 
         dl = MyDownloader(self.files)
@@ -1406,6 +1413,16 @@ class Web(WebMixin, unittest.TestCase):
         d.addCallback(_check2)
         return d
 
+    def test_PUT_NEWDIR_URI(self):
+        d = self.PUT("/uri?t=mkdir", "")
+        def _check(uri):
+            self.failUnless(uri in self.nodes)
+            self.failUnless(isinstance(self.nodes[uri], MyDirectoryNode))
+            return self.GET("/uri/%s?t=json" % uri.replace("/","!"))
+        d.addCallback(_check)
+        d.addCallback(self.failUnlessIsEmptyJSON)
+        return d
+
     def test_XMLRPC(self):
         raise unittest.SkipTest("not yet")
         pass
index 7bafda49a41f1e76ba62984b25a9fafec0e565cc..d9dd29f0fdcd299b6c9352d22d801486b967b1ab 100644 (file)
@@ -60,6 +60,7 @@ class VirtualDrive(service.MultiService):
                      % furl_file)
             return
 
+        self.global_vdrive_furl = global_vdrive_furl
         tub.connectTo(global_vdrive_furl,
                       self._got_vdrive_server, global_vdrive_furl)
 
@@ -157,3 +158,9 @@ class VirtualDrive(service.MultiService):
             return d
 
         return root
+
+    def create_directory(self):
+        # return a new+empty+unlinked dirnode
+        assert self.global_vdrive_furl
+        d = dirnode.create_directory(self.parent, self.global_vdrive_furl)
+        return d