From: Brian Warner Date: Tue, 20 May 2008 01:37:28 +0000 (-0700) Subject: web/directory: fix rw_uri output in t=JSON to reflect mutable files properly X-Git-Tag: allmydata-tahoe-1.1.0~112 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/bcase?a=commitdiff_plain;h=daebb4206019d427e3e79532e9fd4b45ffcebd86;p=tahoe-lafs%2Ftahoe-lafs.git web/directory: fix rw_uri output in t=JSON to reflect mutable files properly --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 7343ece9..d8faa952 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -911,6 +911,7 @@ class Web(WebMixin, unittest.TestCase): self.failUnless(IMutableFileNode.providedBy(newnode)) self.failUnless(newnode.is_mutable()) self.failIf(newnode.is_readonly()) + self._mutable_node = newnode self._mutable_uri = newnode.get_uri() d.addCallback(_got) @@ -976,6 +977,21 @@ class Web(WebMixin, unittest.TestCase): self.failUnlessEqual(self._mutable_uri, newnode.get_uri()) d.addCallback(_got3) + d.addCallback(lambda res: + self.GET(self.public_url + "/foo/?t=json", + followRedirect=True)) + def _check_page_json(res): + parsed = simplejson.loads(res) + self.failUnlessEqual(parsed[0], "dirnode") + children = parsed[1]["children"] + self.failUnless("new.txt" in children) + new_json = children["new.txt"] + self.failUnlessEqual(new_json[0], "filenode") + self.failUnlessEqual(new_json[1]["rw_uri"], self._mutable_uri) + ro_uri = unicode(self._mutable_node.get_readonly().to_string()) + self.failUnlessEqual(new_json[1]["ro_uri"], ro_uri) + d.addCallback(_check_page_json) + d.addErrback(self.dump_error) return d diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index 8397541b..8e7c021a 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -627,28 +627,36 @@ def DirectoryJSONMetadata(ctx, dirnode): def _got(children): kids = {} for name, (childnode, metadata) in children.iteritems(): + if childnode.is_readonly(): + rw_uri = None + ro_uri = childnode.get_uri() + else: + rw_uri = childnode.get_uri() + ro_uri = childnode.get_readonly_uri() if IFileNode.providedBy(childnode): - kiduri = childnode.get_uri() - kiddata = ("filenode", - {'ro_uri': kiduri, - 'size': childnode.get_size(), - 'metadata': metadata, - }) + kiddata = ("filenode", {'size': childnode.get_size(), + 'metadata': metadata, + }) else: assert IDirectoryNode.providedBy(childnode), (childnode, children,) - kiddata = ("dirnode", - {'ro_uri': childnode.get_readonly_uri(), - 'metadata': metadata, - }) - if not childnode.is_readonly(): - kiddata[1]['rw_uri'] = childnode.get_uri() + kiddata = ("dirnode", {'metadata': metadata}) + if ro_uri: + kiddata[1]["ro_uri"] = ro_uri + if rw_uri: + kiddata[1]["rw_uri"] = rw_uri kids[name] = kiddata - contents = { 'children': kids, - 'ro_uri': dirnode.get_readonly_uri(), - } - if not dirnode.is_readonly(): - contents['rw_uri'] = dirnode.get_uri() + if dirnode.is_readonly(): + drw_uri = None + dro_uri = dirnode.get_uri() + else: + drw_uri = dirnode.get_uri() + dro_uri = dirnode.get_readonly_uri() + contents = { 'children': kids } + if dro_uri: + contents['ro_uri'] = dro_uri + if drw_uri: + contents['rw_uri'] = drw_uri data = ("dirnode", contents) return simplejson.dumps(data, indent=1) d.addCallback(_got)