From: Brian Warner Date: Sun, 27 Dec 2009 23:21:49 +0000 (-0500) Subject: addendum to "Fix 'tahoe ls' on files (#771)" X-Git-Tag: trac-4200~58 X-Git-Url: https://git.rkrishnan.org/simplejson/components/com_hotproperty/install.html?a=commitdiff_plain;h=00d0ca3902b87cbea9f5976284e1ebf5ca7b4a1c;p=tahoe-lafs%2Ftahoe-lafs.git addendum to "Fix 'tahoe ls' on files (#771)" tahoe_ls.py: tolerate missing metadata web/filenode.py: minor cleanups test_cli.py: test 'tahoe ls FILECAP' --- diff --git a/src/allmydata/scripts/tahoe_ls.py b/src/allmydata/scripts/tahoe_ls.py index 88bbde96..6d71c713 100644 --- a/src/allmydata/scripts/tahoe_ls.py +++ b/src/allmydata/scripts/tahoe_ls.py @@ -53,6 +53,8 @@ def list(options): elif nodetype == "filenode": childname = path.split("/")[-1] children = {childname: (nodetype, d)} + if "metadata" not in d: + d["metadata"] = {} childnames = sorted(children.keys()) now = time.time() diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index 3c5829f9..ee6770cf 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -748,12 +748,16 @@ class List(GridTestMixin, CLITestMixin, unittest.TestCase): self.basedir = "cli/List/list" self.set_up_grid() c0 = self.g.clients[0] + small = "small" d = c0.create_dirnode() def _stash_root_and_create_file(n): self.rootnode = n self.rooturi = n.get_uri() - return n.add_file(u"good", upload.Data("small", convergence="")) + return n.add_file(u"good", upload.Data(small, convergence="")) d.addCallback(_stash_root_and_create_file) + def _stash_goodcap(n): + self.goodcap = n.get_uri() + d.addCallback(_stash_goodcap) d.addCallback(lambda ign: self.rootnode.create_subdirectory(u"1share")) d.addCallback(lambda n: self.delete_shares_numbered(n.get_uri(), range(1,10))) @@ -786,10 +790,21 @@ class List(GridTestMixin, CLITestMixin, unittest.TestCase): d.addCallback(lambda ign: self.do_cli("ls", "0share")) d.addCallback(_check3) def _check4((rc, out, err)): + # listing a file (as dir/filename) should have the edge metadata, + # including the filename self.failUnlessEqual(rc, 0) self.failUnlessIn("good", out) - d.addCallback(lambda ign: self.do_cli("ls", "good")) + self.failIfIn("-r-- %d -" % len(small), out, + "trailing hyphen means unknown date") + d.addCallback(lambda ign: self.do_cli("ls", "-l", "good")) d.addCallback(_check4) + def _check5((rc, out, err)): + # listing a raw filecap should not explode, but it will have no + # metadata, just the size + self.failUnlessEqual(rc, 0) + self.failUnlessEqual("-r-- %d -" % len(small), out.strip()) + d.addCallback(lambda ign: self.do_cli("ls", "-l", self.goodcap)) + d.addCallback(_check5) return d class Mv(GridTestMixin, CLITestMixin, unittest.TestCase): diff --git a/src/allmydata/web/filenode.py b/src/allmydata/web/filenode.py index b6a9a790..9fd44022 100644 --- a/src/allmydata/web/filenode.py +++ b/src/allmydata/web/filenode.py @@ -426,7 +426,7 @@ class FileDownloader(rend.Page): return req.deferred -def FileJSONMetadata(ctx, filenode, edge_metadata=None): +def FileJSONMetadata(ctx, filenode, edge_metadata): if filenode.is_readonly(): rw_uri = None ro_uri = filenode.get_uri() @@ -443,8 +443,8 @@ def FileJSONMetadata(ctx, filenode, edge_metadata=None): if verifycap: data[1]['verify_uri'] = verifycap.to_string() data[1]['mutable'] = filenode.is_mutable() - if edge_metadata: - data[1]["metadata"] = edge_metadata + if edge_metadata is not None: + data[1]['metadata'] = edge_metadata return text_plain(simplejson.dumps(data, indent=1) + "\n", ctx) def FileURI(ctx, filenode):