]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
web: handle PUT mutable=true properly
authorBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 19:36:02 +0000 (12:36 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 19:36:02 +0000 (12:36 -0700)
src/allmydata/test/test_web.py
src/allmydata/web/filenode.py

index 4f089d1b438458aa4b66ee3b79ff37fef2f2bedc..313f4fc6b9e0e7f248970052316b2a94f3d94a8c 100644 (file)
@@ -587,6 +587,24 @@ class Web(WebMixin, unittest.TestCase):
                                                       self.NEWFILE_CONTENTS))
         return d
 
+    def test_PUT_NEWFILEURL_mutable(self):
+        d = self.PUT(self.public_url + "/foo/new.txt?mutable=true",
+                     self.NEWFILE_CONTENTS)
+        # TODO: we lose the response code, so we can't check this
+        #self.failUnlessEqual(responsecode, 201)
+        def _check_uri(res):
+            u = uri.from_string_mutable_filenode(res)
+            self.failUnless(u.is_mutable())
+            self.failIf(u.is_readonly())
+            return res
+        d.addCallback(_check_uri)
+        d.addCallback(self.failUnlessURIMatchesChild, self._foo_node, u"new.txt")
+        d.addCallback(lambda res:
+                      self.failUnlessMutableChildContentsAre(self._foo_node,
+                                                             u"new.txt",
+                                                             self.NEWFILE_CONTENTS))
+        return d
+
     def test_PUT_NEWFILEURL_replace(self):
         d = self.PUT(self.public_url + "/foo/bar.txt", self.NEWFILE_CONTENTS)
         # TODO: we lose the response code, so we can't check this
index 751e097b2416909c054f57c928e3bd8fcecd661e..013c1e06d51451f2d166b91bf3556d58195eb394 100644 (file)
@@ -22,8 +22,21 @@ class ReplaceMeMixin:
         # a new file is being uploaded in our place.
         req = IRequest(ctx)
         client = IClient(ctx)
-        uploadable = FileHandle(req.content, convergence=client.convergence)
-        d = self.parentnode.add_file(self.name, uploadable, overwrite=replace)
+        mutable = boolean_of_arg(get_arg(req, "mutable", "false"))
+        if mutable:
+            req.content.seek(0)
+            data = req.content.read()
+            d = client.create_mutable_file(data)
+            def _uploaded(newnode):
+                d2 = self.parentnode.set_node(self.name, newnode,
+                                              overwrite=replace)
+                d2.addCallback(lambda res: newnode)
+                return d2
+            d.addCallback(_uploaded)
+        else:
+            uploadable = FileHandle(req.content, convergence=client.convergence)
+            d = self.parentnode.add_file(self.name, uploadable,
+                                         overwrite=replace)
         def _done(filenode):
             log.msg("webish upload complete",
                     facility="tahoe.webish", level=log.NOISY)