]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
dirnode.set_children: take a dict, not a list
authorBrian Warner <warner@lothar.com>
Tue, 13 Oct 2009 00:24:40 +0000 (17:24 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 13 Oct 2009 00:24:40 +0000 (17:24 -0700)
src/allmydata/dirnode.py
src/allmydata/interfaces.py
src/allmydata/test/test_deepcheck.py
src/allmydata/test/test_dirnode.py
src/allmydata/web/directory.py

index 20faef2eccd0f7c3495ae6342bde18a0f1d65261..8dc9139c17fd03f1776f2c55446a894d27e119a3 100644 (file)
@@ -400,14 +400,14 @@ class DirectoryNode:
         # this takes URIs
         a = Adder(self, overwrite=overwrite)
         node_entries = []
-        for e in entries:
-            if len(e) == 3:
-                name, writecap, readcap = e
+        for (name, e) in entries.iteritems():
+            assert isinstance(name, unicode)
+            if len(e) == 2:
+                writecap, readcap = e
                 metadata = None
             else:
-                assert len(e) == 4
-                name, writecap, readcap, metadata = e
-            assert isinstance(name, unicode)
+                assert len(e) == 3
+                writecap, readcap, metadata = e
             precondition(isinstance(writecap, (str,type(None))), writecap)
             precondition(isinstance(readcap, (str,type(None))), readcap)
             child_node = self._create_node(writecap, readcap)
index ce6bc5b2e267b7aca94a836d0c4e0392335d666f..d2a93e3e37fbc318e324983e8ebf41e7f8b1b56c 100644 (file)
@@ -898,10 +898,11 @@ class IDirectoryNode(IMutableFilesystemNode):
         NotMutableError."""
 
     def set_children(entries, overwrite=True):
-        """Add multiple (name, writecap, readcap) triples (or (name,
-        writecap, readcap, metadata) 4-tuples) to a directory node. Returns a
-        Deferred that fires (with None) when the operation finishes. This is
-        equivalent to calling set_uri() multiple times, but is much more
+        """Add multiple children (by writecap+readcap) to a directory node.
+        Takes a dictionary, with childname as keys and (writecap, readcap)
+        tuples (or (writecap, readcap, metadata) triples) as values. Returns
+        a Deferred that fires (with None) when the operation finishes. This
+        is equivalent to calling set_uri() multiple times, but is much more
         efficient. All child names must be unicode strings.
         """
 
index be3f35a698f7d9b186377e5c119db9d426f71651..0ec2ef843afc4fa9e69c617fc0c2dffff655df5e 100644 (file)
@@ -1184,10 +1184,10 @@ class Large(DeepCheckBase, unittest.TestCase):
         d.addCallback(lambda root: root.create_empty_directory(u"subdir"))
         def _add_children(subdir_node):
             self.subdir_node = subdir_node
-            kids = []
+            kids = {}
             for i in range(1, COUNT):
                 litcap = LiteralFileURI("%03d-data" % i).to_string()
-                kids.append( (u"%03d-small" % i, litcap, litcap) )
+                kids[u"%03d-small" % i] = (litcap, litcap)
             return subdir_node.set_children(kids)
         d.addCallback(_add_children)
         up = upload.Data("large enough for CHK" * 100, "")
index aee125bf25f3be9a55c8e96b40396a9cdbbaee17..b4c2f76025c15dbaef7eaf188374d4e88acde2de 100644 (file)
@@ -449,18 +449,21 @@ class Dirnode(GridTestMixin, unittest.TestCase,
 
             # metadata through set_children()
             d.addCallback(lambda res:
-                          n.set_children([
-                              (u"e1", fake_file_uri, fake_file_uri),
-                              (u"e2", fake_file_uri, fake_file_uri, {}),
-                              (u"e3", fake_file_uri, fake_file_uri,
-                               {"key": "value"}),
-                              ]))
+                          n.set_children({
+                              u"e1": (fake_file_uri, fake_file_uri),
+                              u"e2": (fake_file_uri, fake_file_uri, {}),
+                              u"e3": (fake_file_uri, fake_file_uri,
+                                      {"key": "value"}),
+                              }))
             d.addCallback(lambda res:
                           self.shouldFail(ExistingChildError, "set_children-no",
                                           "child 'e1' already exists",
                                           n.set_children,
-                                          [ (u"e1", other_file_uri, other_file_uri),
-                                            (u"new", other_file_uri, other_file_uri), ],
+                                          { u"e1": (other_file_uri,
+                                                    other_file_uri),
+                                            u"new": (other_file_uri,
+                                                     other_file_uri),
+                                            },
                                           overwrite=False))
             # and 'new' should not have been created
             d.addCallback(lambda res: n.list())
index 89b0872533ca05fe121a96c94dd7ec80b62c6a59..37dc574b77500bef8106347abd38e39ceff159ef 100644 (file)
@@ -467,7 +467,7 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
             le.args = tuple(le.args + (body,))
             # TODO test handling of bad JSON
             raise
-        cs = []
+        cs = {}
         for name, (file_or_dir, mddict) in children.iteritems():
             name = unicode(name) # simplejson-2.0.1 returns str *or* unicode
             writecap = mddict.get('rw_uri')
@@ -476,7 +476,7 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
             readcap = mddict.get('ro_uri')
             if readcap is not None:
                 readcap = str(readcap)
-            cs.append((name, writecap, readcap, mddict.get('metadata')))
+            cs[name] = (writecap, readcap, mddict.get('metadata'))
         d = self.node.set_children(cs, replace)
         d.addCallback(lambda res: "Okay so I did it.")
         # TODO: results