]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Fix 'tahoe ls' on files (#771). Patch adapted from Kevan Carstensen.
authorBrian Warner <warner@lothar.com>
Sun, 27 Dec 2009 22:54:43 +0000 (17:54 -0500)
committerBrian Warner <warner@lothar.com>
Sun, 27 Dec 2009 22:54:43 +0000 (17:54 -0500)
web/filenode.py: also serve edge metadata when using t=json on a
                 DIRCAP/childname object.
tahoe_ls.py: list file objects as if we were listing one-entry directories.
             Show edge metadata if we have it, which will be true when doing
             'tahoe ls DIRCAP/filename' and false when doing 'tahoe ls
             FILECAP'

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

index 1552da426a2855bef13d108024c66ff1a8376c09..88bbde96add96aa1c1f466fc557d72079ffcd4eb 100644 (file)
@@ -52,7 +52,7 @@ def list(options):
         children = d['children']
     elif nodetype == "filenode":
         childname = path.split("/")[-1]
-        children = {childname: d}
+        children = {childname: (nodetype, d)}
     childnames = sorted(children.keys())
     now = time.time()
 
index fd12128cdeab2a4aafeeeb3350e58a1ff1cc7671..3c5829f92ee0d327b31b68c60388c467ee17af6c 100644 (file)
@@ -785,6 +785,11 @@ class List(GridTestMixin, CLITestMixin, unittest.TestCase):
         d.addCallback(_check3)
         d.addCallback(lambda ign: self.do_cli("ls", "0share"))
         d.addCallback(_check3)
+        def _check4((rc, out, err)):
+            self.failUnlessEqual(rc, 0)
+            self.failUnlessIn("good", out)
+        d.addCallback(lambda ign: self.do_cli("ls", "good"))
+        d.addCallback(_check4)
         return d
 
 class Mv(GridTestMixin, CLITestMixin, unittest.TestCase):
index fd5e994200787fc915357b9a7068f2bd0b17aeb1..529afe76f948ae50421b4c5661914094057bf0d0 100644 (file)
@@ -860,13 +860,26 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, unittest.TestCase):
         d.addBoth(self.should404, "test_DELETE_FILEURL_missing2")
         return d
 
+    def failUnlessHasBarDotTxtMetadata(self, res):
+        data = simplejson.loads(res)
+        self.failUnless(isinstance(data, list))
+        self.failUnless(data[1].has_key("metadata"))
+        self.failUnless(data[1]["metadata"].has_key("ctime"))
+        self.failUnless(data[1]["metadata"].has_key("mtime"))
+        self.failUnlessEqual(data[1]["metadata"]["ctime"],
+                             self._bar_txt_metadata["ctime"])
+
     def test_GET_FILEURL_json(self):
         # twisted.web.http.parse_qs ignores any query args without an '=', so
         # I can't do "GET /path?json", I have to do "GET /path/t=json"
         # instead. This may make it tricky to emulate the S3 interface
         # completely.
         d = self.GET(self.public_url + "/foo/bar.txt?t=json")
-        d.addCallback(self.failUnlessIsBarJSON)
+        def _check1(data):
+            self.failUnlessIsBarJSON(data)
+            self.failUnlessHasBarDotTxtMetadata(data)
+            return
+        d.addCallback(_check1)
         return d
 
     def test_GET_FILEURL_json_missing(self):
index daf3d43ff592421ed10edba03e939d33f71f297d..b6a9a79029693609b6250f4d587a54a6e6cf508d 100644 (file)
@@ -186,7 +186,12 @@ class FileNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
             d.addCallback(lambda dn: FileDownloader(dn, filename))
             return d
         if t == "json":
-            return FileJSONMetadata(ctx, self.node)
+            if self.parentnode and self.name:
+                d = self.parentnode.get_metadata_for(self.name)
+            else:
+                d = defer.succeed(None)
+            d.addCallback(lambda md: FileJSONMetadata(ctx, self.node, md))
+            return d
         if t == "info":
             return MoreInfo(self.node)
         if t == "uri":
@@ -421,7 +426,7 @@ class FileDownloader(rend.Page):
         return req.deferred
 
 
-def FileJSONMetadata(ctx, filenode):
+def FileJSONMetadata(ctx, filenode, edge_metadata=None):
     if filenode.is_readonly():
         rw_uri = None
         ro_uri = filenode.get_uri()
@@ -438,6 +443,8 @@ def FileJSONMetadata(ctx, filenode):
     if verifycap:
         data[1]['verify_uri'] = verifycap.to_string()
     data[1]['mutable'] = filenode.is_mutable()
+    if edge_metadata:
+        data[1]["metadata"] = edge_metadata
     return text_plain(simplejson.dumps(data, indent=1) + "\n", ctx)
 
 def FileURI(ctx, filenode):