Changeset e2ffc3d in trunk for src/allmydata
- Timestamp:
- 2009-10-12T23:51:26Z (16 years ago)
- Branches:
- master
- Children:
- 304aadd4
- Parents:
- 3ee7406
- Location:
- src/allmydata
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/dirnode.py ¶
r3ee7406 re2ffc3d 381 381 return d 382 382 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): 393 384 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) 396 388 if isinstance(child_node, UnknownNode): 397 389 # don't be willing to pack unknown nodes: we might accidentally … … 410 402 node_entries = [] 411 403 for e in entries: 412 if len(e) == 2:413 name, child_uri= e404 if len(e) == 3: 405 name, writecap, readcap = e 414 406 metadata = None 415 407 else: 416 assert len(e) == 3417 name, child_uri, metadata = e408 assert len(e) == 4 409 name, writecap, readcap, metadata = e 418 410 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) 421 414 if isinstance(child_node, UnknownNode): 422 415 msg = "cannot pack unknown node as child %s" % str(name) -
TabularUnified src/allmydata/interfaces.py ¶
r3ee7406 re2ffc3d 874 874 """ 875 875 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(). 885 889 886 890 If metadata= is provided, I will use it as the metadata for the named … … 895 899 896 900 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 fires899 (with None) when the operation finishes. This is equivalent to900 calling set_uri() multiple times, but is much more efficient. All901 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. 902 906 """ 903 907 -
TabularUnified src/allmydata/test/test_deepcheck.py ¶
r3ee7406 re2ffc3d 1187 1187 kids = [] 1188 1188 for i in range(1, COUNT): 1189 lit node= LiteralFileURI("%03d-data" % i).to_string()1190 kids.append( (u"%03d-small" % i, lit node) )1189 litcap = LiteralFileURI("%03d-data" % i).to_string() 1190 kids.append( (u"%03d-small" % i, litcap, litcap) ) 1191 1191 return subdir_node.set_children(kids) 1192 1192 d.addCallback(_add_children) -
TabularUnified src/allmydata/test/test_dirnode.py ¶
r3ee7406 re2ffc3d 68 68 d.addCallback(lambda dn: 69 69 self._rootnode.set_uri(u"rodir", 70 dn.get_uri(), 70 71 dn.get_readonly_uri())) 71 72 return d … … 160 161 d = c.create_dirnode() 161 162 def _created(rw_dn): 162 d2 = rw_dn.set_uri(u"child", filecap )163 d2 = rw_dn.set_uri(u"child", filecap, filecap) 163 164 d2.addCallback(lambda res: rw_dn) 164 165 return d2 … … 172 173 173 174 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) 175 176 self.shouldFail(dirnode.NotMutableError, "set_uri ro", None, 176 177 ro_dn.set_node, u"newchild", filenode) … … 244 245 self.expected_verifycaps.add(ffu_v) 245 246 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)) 247 249 d.addCallback(lambda res: 248 250 self.shouldFail(ExistingChildError, "set_uri-no", 249 251 "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, 251 254 overwrite=False)) 252 255 # / … … 374 377 # set_uri + metadata 375 378 # 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 {})) 377 382 d.addCallback(lambda res: n.get_metadata_for(u"c2")) 378 383 d.addCallback(lambda metadata: self.failUnlessEqual(metadata.keys(), ['tahoe'])) 379 384 380 385 # 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"}})) 382 389 d.addCallback(lambda res: n.get_metadata_for(u"c2")) 383 390 def _has_good_linkcrtime(metadata): … … 388 395 389 396 # 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)) 391 399 d.addCallback(lambda res: n.get_metadata_for(u"c3")) 392 400 d.addCallback(lambda metadata: … … 396 404 # or we can add specific metadata at set_uri() time, which 397 405 # 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, 399 408 {"key": "value"})) 400 409 d.addCallback(lambda res: n.get_metadata_for(u"c4")) … … 440 449 441 450 # 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 ])) 447 458 d.addCallback(lambda res: 448 459 self.shouldFail(ExistingChildError, "set_children-no", 449 460 "child 'e1' already exists", 450 461 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), ], 453 464 overwrite=False)) 454 465 # and 'new' should not have been created … … 646 657 # now make sure that we honor overwrite=False 647 658 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)) 649 661 650 662 d.addCallback(lambda res: … … 805 817 "copy unknown", 806 818 "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)) 808 821 d.addCallback(lambda ign: self._node.list()) 809 822 def _check(children): -
TabularUnified src/allmydata/test/test_system.py ¶
r3ee7406 re2ffc3d 863 863 d1.addCallback(lambda res: rootnode.get_child_at_path([u"subdir1", u"subdir2"])) 864 864 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())) 867 871 return d2 868 872 d1.addCallback(_got_s2) … … 945 949 d1.addCallback(lambda res: self.shouldFail2(NotMutableError, "delete(nope)", None, dirnode.delete, u"mydata992")) 946 950 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)) 948 952 949 953 d1.addCallback(lambda res: self.shouldFail2(NoSuchChildError, "get(missing)", "missing", dirnode.get, u"missing")) -
TabularUnified src/allmydata/test/test_web.py ¶
r3ee7406 re2ffc3d 137 137 # NOTE: we ignore the deferred on all set_uri() calls, because we 138 138 # 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()) 140 141 141 142 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) 143 144 self._bar_txt_verifycap = n.get_verify_cap().to_string() 144 145 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()) 146 148 sub_uri = res[4][1].get_uri() 147 149 self._sub_uri = sub_uri 148 foo.set_uri(u"sub", sub_uri )150 foo.set_uri(u"sub", sub_uri, sub_uri) 149 151 sub = self.s.create_node_from_uri(sub_uri) 150 152 151 153 _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) 153 155 154 156 unicode_filename = u"n\u00fc.txt" # n u-umlaut . t x t 155 157 # ok, unicode calls it LATIN SMALL LETTER U WITH DIAERESIS but I 156 158 # 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) 158 160 159 161 _ign, n, baz_file = self.makefile(2) 160 162 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) 162 164 163 165 _ign, n, self._bad_file_uri = self.makefile(3) … … 166 168 167 169 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) 170 173 171 174 # public/ -
TabularUnified src/allmydata/web/directory.py ¶
r3ee7406 re2ffc3d 205 205 d = self._POST_stream_manifest(ctx) 206 206 elif t == "set_children": 207 # TODO: docs208 207 d = self._POST_set_children(req) 209 208 else: … … 304 303 name = name.decode(charset) 305 304 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) 307 306 d.addCallback(lambda res: childcap) 308 307 return d … … 472 471 for name, (file_or_dir, mddict) in children.iteritems(): 473 472 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'))) 476 480 d = self.node.set_children(cs, replace) 477 481 d.addCallback(lambda res: "Okay so I did it.")
Note: See TracChangeset
for help on using the changeset viewer.