From: Brian Warner Date: Tue, 20 May 2008 19:36:02 +0000 (-0700) Subject: web: handle PUT mutable=true properly X-Git-Tag: allmydata-tahoe-1.1.0~101 X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/frontends/FTP-and-SFTP.rst?a=commitdiff_plain;h=e3230197080d29702f3f509cbf6ae26c45c8c3ad;p=tahoe-lafs%2Ftahoe-lafs.git web: handle PUT mutable=true properly --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 4f089d1b..313f4fc6 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -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 diff --git a/src/allmydata/web/filenode.py b/src/allmydata/web/filenode.py index 751e097b..013c1e06 100644 --- a/src/allmydata/web/filenode.py +++ b/src/allmydata/web/filenode.py @@ -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)