From: Brian Warner Date: Tue, 20 May 2008 22:14:19 +0000 (-0700) Subject: web: fix JSON output for mutable files X-Git-Tag: allmydata-tahoe-1.1.0~93 X-Git-Url: https://git.rkrishnan.org/pf/content/en//%22%22?a=commitdiff_plain;h=8dded7819c2a182241039c909c89e284de13a4ad;p=tahoe-lafs%2Ftahoe-lafs.git web: fix JSON output for mutable files --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 313f4fc6..754b42ec 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -1139,6 +1139,7 @@ class Web(WebMixin, unittest.TestCase): self.failUnlessEqual(self._mutable_uri, newnode.get_uri()) d.addCallback(_got3) + # look at the JSON form of the enclosing directory d.addCallback(lambda res: self.GET(self.public_url + "/foo/?t=json", followRedirect=True)) @@ -1154,6 +1155,17 @@ class Web(WebMixin, unittest.TestCase): self.failUnlessEqual(new_json[1]["ro_uri"], ro_uri) d.addCallback(_check_page_json) + # and the JSON form of the file + d.addCallback(lambda res: + self.GET(self.public_url + "/foo/new.txt?t=json")) + def _check_file_json(res): + parsed = simplejson.loads(res) + self.failUnlessEqual(parsed[0], "filenode") + self.failUnlessEqual(parsed[1]["rw_uri"], self._mutable_uri) + ro_uri = unicode(self._mutable_node.get_readonly().to_string()) + self.failUnlessEqual(parsed[1]["ro_uri"], ro_uri) + d.addCallback(_check_file_json) + # and look at t=uri and t=readonly-uri d.addCallback(lambda res: self.GET(self.public_url + "/foo/new.txt?t=uri")) diff --git a/src/allmydata/web/filenode.py b/src/allmydata/web/filenode.py index 013c1e06..f65af29e 100644 --- a/src/allmydata/web/filenode.py +++ b/src/allmydata/web/filenode.py @@ -368,11 +368,18 @@ class FileDownloader(resource.Resource): return server.NOT_DONE_YET def FileJSONMetadata(ctx, filenode): - file_uri = filenode.get_uri() - data = ("filenode", - {'ro_uri': file_uri, - 'size': filenode.get_size(), - }) + if filenode.is_readonly(): + rw_uri = None + ro_uri = filenode.get_uri() + else: + rw_uri = filenode.get_uri() + ro_uri = filenode.get_readonly_uri() + data = ("filenode", {}) + data[1]['size'] = filenode.get_size() + if ro_uri: + data[1]['ro_uri'] = ro_uri + if rw_uri: + data[1]['rw_uri'] = rw_uri return text_plain(simplejson.dumps(data, indent=1), ctx) def FileURI(ctx, filenode):