From: Brian Warner Date: Thu, 6 Sep 2007 00:23:06 +0000 (-0700) Subject: webish: implement 'PUT /uri?t=mkdir' (to create anonymous dirnodes) X-Git-Url: https://git.rkrishnan.org/pf/content/install.html?a=commitdiff_plain;h=76be4a582c3487ea9a4a6b158332efc7052087d8;p=tahoe-lafs%2Ftahoe-lafs.git webish: implement 'PUT /uri?t=mkdir' (to create anonymous dirnodes) --- diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index e2edc242..e5b08aa5 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -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.""" diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index c691a682..a4f5c579 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -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 diff --git a/src/allmydata/vdrive.py b/src/allmydata/vdrive.py index 7bafda49..d9dd29f0 100644 --- a/src/allmydata/vdrive.py +++ b/src/allmydata/vdrive.py @@ -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