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'
This commit is contained in:
Brian Warner 2009-12-27 18:21:49 -05:00
parent a8a768ef9d
commit 00d0ca3902
3 changed files with 22 additions and 5 deletions

View File

@ -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()

View File

@ -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):

View File

@ -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):