]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
webish: add PUT /uri?mutable=true
authorBrian Warner <warner@allmydata.com>
Wed, 6 Feb 2008 05:18:02 +0000 (22:18 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 6 Feb 2008 05:18:02 +0000 (22:18 -0700)
docs/webapi.txt
src/allmydata/test/test_web.py
src/allmydata/webish.py

index afe35ccedffc3daf37612696d4ea5e6038f67125..3cc00592714f94c1c766e4de2c9bc0f488cc42ea 100644 (file)
@@ -178,7 +178,7 @@ f. uploading a file
 
    This action also uploads a file without attaching it to a virtual drive
    directory, but can be used from an HTML form. The response is the file
-   write cap.
+   read cap.
 
   POST http://localhost:8123/uri?t=upload&mutable=true
 
@@ -186,6 +186,12 @@ f. uploading a file
    directory, but creates a mutable file (SSK) instead of an immutable one.
    The response contains the new URI that was created.
 
+  PUT http://localhost:8123/uri?mutable=true
+
+   This second form also accepts data from the HTTP request body, but creates
+   a mutable file (SSK) instead of an immutable one (CHK). The response
+   contains the new URI that was created.
+
 
 g. creating a new directory
 
index 520dcc3841877ba7b6e03069909a4ed29fae5ebb..af4cb7b3c611702df7eaac946b3b5c447fea88b1 100644 (file)
@@ -1013,6 +1013,7 @@ class Web(WebMixin, unittest.TestCase):
             uri = uri.strip()
             u = IURI(uri)
             self.failUnless(IMutableFileURI.providedBy(u))
+            self.failUnless(u.storage_index in FakeMutableFileNode.all_contents)
             n = self.s.create_node_from_uri(uri)
             return n.download_to_data()
         d.addCallback(_check)
@@ -1541,6 +1542,33 @@ class Web(WebMixin, unittest.TestCase):
                   "/uri only accepts PUT and PUT?t=mkdir")
         return d
 
+    def test_PUT_NEWFILE_URI_mutable(self):
+        file_contents = "New file contents here\n"
+        d = self.PUT("/uri?mutable=true", file_contents)
+        def _check(uri):
+            uri = uri.strip()
+            u = IURI(uri)
+            self.failUnless(IMutableFileURI.providedBy(u))
+            self.failUnless(u.storage_index in FakeMutableFileNode.all_contents)
+            n = self.s.create_node_from_uri(uri)
+            return n.download_to_data()
+        d.addCallback(_check)
+        def _check2(data):
+            self.failUnlessEqual(data, file_contents)
+        d.addCallback(_check2)
+        return d
+
+        def _check(uri):
+            self.failUnless(uri in FakeCHKFileNode.all_contents)
+            self.failUnlessEqual(FakeCHKFileNode.all_contents[uri],
+                                 file_contents)
+            return self.GET("/uri/%s" % uri)
+        d.addCallback(_check)
+        def _check2(res):
+            self.failUnlessEqual(res, file_contents)
+        d.addCallback(_check2)
+        return d
+
     def test_PUT_mkdir(self):
         d = self.PUT("/uri?t=mkdir", "")
         def _check(uri):
index 65132317794ef0dc590b2ffe78405d6e98f860ed..8795b05ea4d7b49b677fdd472068db1c353a45b1 100644 (file)
@@ -1203,10 +1203,19 @@ class URIPUTHandler(rend.Page):
         if t == "":
             # "PUT /uri", to create an unlinked file. This is like PUT but
             # without the associated set_uri.
-            uploadable = FileHandle(req.content)
-            d = IClient(ctx).upload(uploadable)
-            d.addCallback(lambda results: results.uri)
-            # that fires with the URI of the new file
+            mutable = bool(get_arg(req, "mutable", "").strip())
+            if mutable:
+                # SDMF: files are small, and we can only upload data
+                contents = req.content
+                contents.seek(0)
+                data = contents.read()
+                d = IClient(ctx).create_mutable_file(data)
+                d.addCallback(lambda n: n.get_uri())
+            else:
+                uploadable = FileHandle(req.content)
+                d = IClient(ctx).upload(uploadable)
+                d.addCallback(lambda results: results.uri)
+                # that fires with the URI of the new file
             return d
 
         if t == "mkdir":