Changeset e2ffc3d in trunk for src/allmydata


Ignore:
Timestamp:
2009-10-12T23:51:26Z (16 years ago)
Author:
Brian Warner <warner@…>
Branches:
master
Children:
304aadd4
Parents:
3ee7406
Message:

dirnode.set_uri/set_children: change signature to take writecap+readcap
instead of a single cap. The webapi t=set_children call benefits too.

Location:
src/allmydata
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/dirnode.py

    r3ee7406 re2ffc3d  
    381381        return d
    382382
    383     def set_uri(self, name, child_uri, metadata=None, overwrite=True):
    384         """I add a child (by URI) at the specific name. I return a Deferred
    385         that fires with the child node when the operation finishes. I will
    386         replace any existing child of the same name.
    387 
    388         The child_uri could be for a file, or for a directory (either
    389         read-write or read-only, using a URI that came from get_uri() ).
    390 
    391         If this directory node is read-only, the Deferred will errback with a
    392         NotMutableError."""
     383    def set_uri(self, name, writecap, readcap, metadata=None, overwrite=True):
    393384        precondition(isinstance(name, unicode), name)
    394         precondition(isinstance(child_uri, str), child_uri)
    395         child_node = self._create_node(child_uri, None)
     385        precondition(isinstance(writecap, (str,type(None))), writecap)
     386        precondition(isinstance(readcap, (str,type(None))), readcap)
     387        child_node = self._create_node(writecap, readcap)
    396388        if isinstance(child_node, UnknownNode):
    397389            # don't be willing to pack unknown nodes: we might accidentally
     
    410402        node_entries = []
    411403        for e in entries:
    412             if len(e) == 2:
    413                 name, child_uri = e
     404            if len(e) == 3:
     405                name, writecap, readcap = e
    414406                metadata = None
    415407            else:
    416                 assert len(e) == 3
    417                 name, child_uri, metadata = e
     408                assert len(e) == 4
     409                name, writecap, readcap, metadata = e
    418410            assert isinstance(name, unicode)
    419             assert isinstance(child_uri, str)
    420             child_node = self._create_node(child_uri, None)
     411            precondition(isinstance(writecap, (str,type(None))), writecap)
     412            precondition(isinstance(readcap, (str,type(None))), readcap)
     413            child_node = self._create_node(writecap, readcap)
    421414            if isinstance(child_node, UnknownNode):
    422415                msg = "cannot pack unknown node as child %s" % str(name)
  • TabularUnified src/allmydata/interfaces.py

    r3ee7406 re2ffc3d  
    874874        """
    875875
    876     def set_uri(name, child_uri, metadata=None, overwrite=True):
    877         """I add a child (by URI) at the specific name. I return a Deferred
    878         that fires when the operation finishes. If overwrite= is True, I will
    879         replace any existing child of the same name, otherwise an existing
    880         child will cause me to return ExistingChildError. The child name must
    881         be a unicode string.
    882 
    883         The child_uri could be for a file, or for a directory (either
    884         read-write or read-only, using a URI that came from get_uri() ).
     876    def set_uri(name, writecap, readcap=None, metadata=None, overwrite=True):
     877        """I add a child (by writecap+readcap) at the specific name. I return
     878        a Deferred that fires when the operation finishes. If overwrite= is
     879        True, I will replace any existing child of the same name, otherwise
     880        an existing child will cause me to return ExistingChildError. The
     881        child name must be a unicode string.
     882
     883        The child caps could be for a file, or for a directory. If the new
     884        child is read/write, you will provide both writecap and readcap. If
     885        the child is read-only, you will provide the readcap write (i.e. the
     886        writecap= and readcap= arguments will both be the child's readcap).
     887        The filecaps are typically obtained from an IFilesystemNode with
     888        get_uri() and get_readonly_uri().
    885889
    886890        If metadata= is provided, I will use it as the metadata for the named
     
    895899
    896900    def set_children(entries, overwrite=True):
    897         """Add multiple (name, child_uri) pairs (or (name, child_uri,
    898         metadata) triples) to a directory node. Returns a Deferred that fires
    899         (with None) when the operation finishes. This is equivalent to
    900         calling set_uri() multiple times, but is much more efficient. All
    901         child names must be unicode strings.
     901        """Add multiple (name, writecap, readcap) triples (or (name,
     902        writecap, readcap, metadata) 4-tuples) to a directory node. Returns a
     903        Deferred that fires (with None) when the operation finishes. This is
     904        equivalent to calling set_uri() multiple times, but is much more
     905        efficient. All child names must be unicode strings.
    902906        """
    903907
  • TabularUnified src/allmydata/test/test_deepcheck.py

    r3ee7406 re2ffc3d  
    11871187            kids = []
    11881188            for i in range(1, COUNT):
    1189                 litnode = LiteralFileURI("%03d-data" % i).to_string()
    1190                 kids.append( (u"%03d-small" % i, litnode) )
     1189                litcap = LiteralFileURI("%03d-data" % i).to_string()
     1190                kids.append( (u"%03d-small" % i, litcap, litcap) )
    11911191            return subdir_node.set_children(kids)
    11921192        d.addCallback(_add_children)
  • TabularUnified src/allmydata/test/test_dirnode.py

    r3ee7406 re2ffc3d  
    6868            d.addCallback(lambda dn:
    6969                          self._rootnode.set_uri(u"rodir",
     70                                                 dn.get_uri(),
    7071                                                 dn.get_readonly_uri()))
    7172            return d
     
    160161        d = c.create_dirnode()
    161162        def _created(rw_dn):
    162             d2 = rw_dn.set_uri(u"child", filecap)
     163            d2 = rw_dn.set_uri(u"child", filecap, filecap)
    163164            d2.addCallback(lambda res: rw_dn)
    164165            return d2
     
    172173
    173174            self.shouldFail(dirnode.NotMutableError, "set_uri ro", None,
    174                             ro_dn.set_uri, u"newchild", filecap)
     175                            ro_dn.set_uri, u"newchild", filecap, filecap)
    175176            self.shouldFail(dirnode.NotMutableError, "set_uri ro", None,
    176177                            ro_dn.set_node, u"newchild", filenode)
     
    244245            self.expected_verifycaps.add(ffu_v)
    245246            self.expected_storage_indexes.add(base32.b2a(m.get_storage_index()))
    246             d.addCallback(lambda res: n.set_uri(u"child", fake_file_uri))
     247            d.addCallback(lambda res: n.set_uri(u"child",
     248                                                fake_file_uri, fake_file_uri))
    247249            d.addCallback(lambda res:
    248250                          self.shouldFail(ExistingChildError, "set_uri-no",
    249251                                          "child 'child' already exists",
    250                                           n.set_uri, u"child", other_file_uri,
     252                                          n.set_uri, u"child",
     253                                          other_file_uri, other_file_uri,
    251254                                          overwrite=False))
    252255            # /
     
    374377            # set_uri + metadata
    375378            # it should be possible to add a child without any metadata
    376             d.addCallback(lambda res: n.set_uri(u"c2", fake_file_uri, {}))
     379            d.addCallback(lambda res: n.set_uri(u"c2",
     380                                                fake_file_uri, fake_file_uri,
     381                                                {}))
    377382            d.addCallback(lambda res: n.get_metadata_for(u"c2"))
    378383            d.addCallback(lambda metadata: self.failUnlessEqual(metadata.keys(), ['tahoe']))
    379384
    380385            # You can't override the link timestamps.
    381             d.addCallback(lambda res: n.set_uri(u"c2", fake_file_uri, { 'tahoe': {'linkcrtime': "bogus"}}))
     386            d.addCallback(lambda res: n.set_uri(u"c2",
     387                                                fake_file_uri, fake_file_uri,
     388                                                { 'tahoe': {'linkcrtime': "bogus"}}))
    382389            d.addCallback(lambda res: n.get_metadata_for(u"c2"))
    383390            def _has_good_linkcrtime(metadata):
     
    388395
    389396            # if we don't set any defaults, the child should get timestamps
    390             d.addCallback(lambda res: n.set_uri(u"c3", fake_file_uri))
     397            d.addCallback(lambda res: n.set_uri(u"c3",
     398                                                fake_file_uri, fake_file_uri))
    391399            d.addCallback(lambda res: n.get_metadata_for(u"c3"))
    392400            d.addCallback(lambda metadata:
     
    396404            # or we can add specific metadata at set_uri() time, which
    397405            # overrides the timestamps
    398             d.addCallback(lambda res: n.set_uri(u"c4", fake_file_uri,
     406            d.addCallback(lambda res: n.set_uri(u"c4",
     407                                                fake_file_uri, fake_file_uri,
    399408                                                {"key": "value"}))
    400409            d.addCallback(lambda res: n.get_metadata_for(u"c4"))
     
    440449
    441450            # metadata through set_children()
    442             d.addCallback(lambda res: n.set_children([ (u"e1", fake_file_uri),
    443                                                    (u"e2", fake_file_uri, {}),
    444                                                    (u"e3", fake_file_uri,
    445                                                     {"key": "value"}),
    446                                                    ]))
     451            d.addCallback(lambda res:
     452                          n.set_children([
     453                              (u"e1", fake_file_uri, fake_file_uri),
     454                              (u"e2", fake_file_uri, fake_file_uri, {}),
     455                              (u"e3", fake_file_uri, fake_file_uri,
     456                               {"key": "value"}),
     457                              ]))
    447458            d.addCallback(lambda res:
    448459                          self.shouldFail(ExistingChildError, "set_children-no",
    449460                                          "child 'e1' already exists",
    450461                                          n.set_children,
    451                                           [ (u"e1", other_file_uri),
    452                                             (u"new", other_file_uri), ],
     462                                          [ (u"e1", other_file_uri, other_file_uri),
     463                                            (u"new", other_file_uri, other_file_uri), ],
    453464                                          overwrite=False))
    454465            # and 'new' should not have been created
     
    646657            # now make sure that we honor overwrite=False
    647658            d.addCallback(lambda res:
    648                           self.subdir2.set_uri(u"newchild", other_file_uri))
     659                          self.subdir2.set_uri(u"newchild",
     660                                               other_file_uri, other_file_uri))
    649661
    650662            d.addCallback(lambda res:
     
    805817                             "copy unknown",
    806818                             "cannot pack unknown node as child add",
    807                              self._node.set_uri, u"add", future_writecap))
     819                             self._node.set_uri, u"add",
     820                             future_writecap, future_readcap))
    808821        d.addCallback(lambda ign: self._node.list())
    809822        def _check(children):
  • TabularUnified src/allmydata/test/test_system.py

    r3ee7406 re2ffc3d  
    863863            d1.addCallback(lambda res: rootnode.get_child_at_path([u"subdir1", u"subdir2"]))
    864864            def _got_s2(s2node):
    865                 d2 = privnode.set_uri(u"s2-rw", s2node.get_uri())
    866                 d2.addCallback(lambda node: privnode.set_uri(u"s2-ro", s2node.get_readonly_uri()))
     865                d2 = privnode.set_uri(u"s2-rw", s2node.get_uri(),
     866                                      s2node.get_readonly_uri())
     867                d2.addCallback(lambda node:
     868                               privnode.set_uri(u"s2-ro",
     869                                                s2node.get_readonly_uri(),
     870                                                s2node.get_readonly_uri()))
    867871                return d2
    868872            d1.addCallback(_got_s2)
     
    945949            d1.addCallback(lambda res: self.shouldFail2(NotMutableError, "delete(nope)", None, dirnode.delete, u"mydata992"))
    946950
    947             d1.addCallback(lambda res: self.shouldFail2(NotMutableError, "set_uri(nope)", None, dirnode.set_uri, u"hopeless", self.uri))
     951            d1.addCallback(lambda res: self.shouldFail2(NotMutableError, "set_uri(nope)", None, dirnode.set_uri, u"hopeless", self.uri, self.uri))
    948952
    949953            d1.addCallback(lambda res: self.shouldFail2(NoSuchChildError, "get(missing)", "missing", dirnode.get, u"missing"))
  • TabularUnified src/allmydata/test/test_web.py

    r3ee7406 re2ffc3d  
    137137            # NOTE: we ignore the deferred on all set_uri() calls, because we
    138138            # know the fake nodes do these synchronously
    139             self.public_root.set_uri(u"foo", foo.get_uri())
     139            self.public_root.set_uri(u"foo", foo.get_uri(),
     140                                     foo.get_readonly_uri())
    140141
    141142            self.BAR_CONTENTS, n, self._bar_txt_uri = self.makefile(0)
    142             foo.set_uri(u"bar.txt", self._bar_txt_uri)
     143            foo.set_uri(u"bar.txt", self._bar_txt_uri, self._bar_txt_uri)
    143144            self._bar_txt_verifycap = n.get_verify_cap().to_string()
    144145
    145             foo.set_uri(u"empty", res[3][1].get_uri())
     146            foo.set_uri(u"empty", res[3][1].get_uri(),
     147                        res[3][1].get_readonly_uri())
    146148            sub_uri = res[4][1].get_uri()
    147149            self._sub_uri = sub_uri
    148             foo.set_uri(u"sub", sub_uri)
     150            foo.set_uri(u"sub", sub_uri, sub_uri)
    149151            sub = self.s.create_node_from_uri(sub_uri)
    150152
    151153            _ign, n, blocking_uri = self.makefile(1)
    152             foo.set_uri(u"blockingfile", blocking_uri)
     154            foo.set_uri(u"blockingfile", blocking_uri, blocking_uri)
    153155
    154156            unicode_filename = u"n\u00fc.txt" # n u-umlaut . t x t
    155157            # ok, unicode calls it LATIN SMALL LETTER U WITH DIAERESIS but I
    156158            # still think of it as an umlaut
    157             foo.set_uri(unicode_filename, self._bar_txt_uri)
     159            foo.set_uri(unicode_filename, self._bar_txt_uri, self._bar_txt_uri)
    158160
    159161            _ign, n, baz_file = self.makefile(2)
    160162            self._baz_file_uri = baz_file
    161             sub.set_uri(u"baz.txt", baz_file)
     163            sub.set_uri(u"baz.txt", baz_file, baz_file)
    162164
    163165            _ign, n, self._bad_file_uri = self.makefile(3)
     
    166168
    167169            rodir = res[5][1]
    168             self.public_root.set_uri(u"reedownlee", rodir.get_readonly_uri())
    169             rodir.set_uri(u"nor", baz_file)
     170            self.public_root.set_uri(u"reedownlee", rodir.get_readonly_uri(),
     171                                     rodir.get_readonly_uri())
     172            rodir.set_uri(u"nor", baz_file, baz_file)
    170173
    171174            # public/
  • TabularUnified src/allmydata/web/directory.py

    r3ee7406 re2ffc3d  
    205205            d = self._POST_stream_manifest(ctx)
    206206        elif t == "set_children":
    207             # TODO: docs
    208207            d = self._POST_set_children(req)
    209208        else:
     
    304303        name = name.decode(charset)
    305304        replace = boolean_of_arg(get_arg(req, "replace", "true"))
    306         d = self.node.set_uri(name, childcap, overwrite=replace)
     305        d = self.node.set_uri(name, childcap, childcap, overwrite=replace)
    307306        d.addCallback(lambda res: childcap)
    308307        return d
     
    472471        for name, (file_or_dir, mddict) in children.iteritems():
    473472            name = unicode(name) # simplejson-2.0.1 returns str *or* unicode
    474             cap = str(mddict.get('rw_uri') or mddict.get('ro_uri'))
    475             cs.append((name, cap, mddict.get('metadata')))
     473            writecap = mddict.get('rw_uri')
     474            if writecap is not None:
     475                writecap = str(writecap)
     476            readcap = mddict.get('ro_uri')
     477            if readcap is not None:
     478                readcap = str(readcap)
     479            cs.append((name, writecap, readcap, mddict.get('metadata')))
    476480        d = self.node.set_children(cs, replace)
    477481        d.addCallback(lambda res: "Okay so I did it.")
Note: See TracChangeset for help on using the changeset viewer.