]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
addendum to "Fix 'tahoe ls' on files (#771)"
authorBrian Warner <warner@lothar.com>
Sun, 27 Dec 2009 23:21:49 +0000 (18:21 -0500)
committerBrian Warner <warner@lothar.com>
Sun, 27 Dec 2009 23:21:49 +0000 (18:21 -0500)
tahoe_ls.py: tolerate missing metadata
web/filenode.py: minor cleanups
test_cli.py: test 'tahoe ls FILECAP'

src/allmydata/scripts/tahoe_ls.py
src/allmydata/test/test_cli.py
src/allmydata/web/filenode.py

index 88bbde96add96aa1c1f466fc557d72079ffcd4eb..6d71c713415f997061789097052e3fc2955ae3c7 100644 (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()
 
index 3c5829f92ee0d327b31b68c60388c467ee17af6c..ee6770cfaa4895c93129a0dc85e550c9170aafc7 100644 (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):
index b6a9a79029693609b6250f4d587a54a6e6cf508d..9fd44022a61404a2ac843140a2a0bb313676623b 100644 (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):