From: Brian Warner Date: Fri, 17 Aug 2007 00:03:19 +0000 (-0700) Subject: dirnode: change the defined behavior of RIVirtualDriveServer.set to allow replace... X-Git-Url: https://git.rkrishnan.org/simplejson/%22news.html/module-simplejson.tests.html?a=commitdiff_plain;h=fe06b3be8bb5d23094fbd267c697f25ed1a7010f;p=tahoe-lafs%2Ftahoe-lafs.git dirnode: change the defined behavior of RIVirtualDriveServer.set to allow replace-in-place without raising an exception --- diff --git a/src/allmydata/dirnode.py b/src/allmydata/dirnode.py index b3d6d826..bdbea6ab 100644 --- a/src/allmydata/dirnode.py +++ b/src/allmydata/dirnode.py @@ -14,8 +14,6 @@ from allmydata.Crypto.Cipher import AES class BadWriteEnablerError(Exception): pass -class ChildAlreadyPresentError(Exception): - pass class NoPublicRootError(Exception): pass @@ -107,7 +105,11 @@ class VirtualDriveServer(service.MultiService, Referenceable): # first, see if the key is already present for i,(H_key, E_key, E_write, E_read) in enumerate(data[1]): if H_key == key: - raise ChildAlreadyPresentError + # it is, we need to remove it first. Recurse to complete the + # operation. + self.delete(index, write_enabler, key) + return self.set(index, write_enabler, key, + name, write, read) # now just append the data data[1].append( (key, name, write, read) ) self._write_to_file(index, data) diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index b8369d47..785b7477 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -247,10 +247,8 @@ class RIVirtualDriveServer(RemoteInterface): def set(index=Hash, write_enabler=Hash, key=Hash, name=EncryptedThing, write=EncryptedThing, read=EncryptedThing): - """Set a child object. - - This will raise IndexError if a child with the given name already - exists. + """Set a child object. I will replace any existing child of the same + name. """ def delete(index=Hash, write_enabler=Hash, key=Hash): @@ -373,7 +371,8 @@ class IDirectoryNode(Interface): def set_uri(name, child_uri): """I add a child (by URI) at the specific name. I return a Deferred - that fires when the operation finishes. + that fires when the operation finishes. I will replace any existing + child of the same name. The child_uri could be for a file, or for a directory (either read-write or read-only, using a URI that came from get_uri() ). @@ -384,7 +383,8 @@ class IDirectoryNode(Interface): def set_node(name, child): """I add a child at the specific name. I return a Deferred that fires when the operation finishes. This Deferred will fire with the child - node that was just added. + node that was just added. I will replace any existing child of the + same name. If this directory node is read-only, the Deferred will errback with a NotMutableError.""" diff --git a/src/allmydata/test/test_dirnode.py b/src/allmydata/test/test_dirnode.py index 47e1eb5d..fb753f3a 100644 --- a/src/allmydata/test/test_dirnode.py +++ b/src/allmydata/test/test_dirnode.py @@ -9,7 +9,7 @@ from allmydata.util import hashutil from allmydata.interfaces import IDirectoryNode, IDirnodeURI from allmydata.scripts import runner from allmydata.dirnode import VirtualDriveServer, \ - ChildAlreadyPresentError, BadWriteEnablerError, NoPublicRootError + BadWriteEnablerError, NoPublicRootError # test the host-side code @@ -31,12 +31,10 @@ class DirectoryNode(unittest.TestCase): self.failUnlessEqual(empty_list, []) vds.set(index, we, "key1", "name1", "write1", "read1") + vds.set(index, we, "key2", "name2", "write2", "read2") + # we should be able to replace entries without complaint vds.set(index, we, "key2", "name2", "", "read2") - self.failUnlessRaises(ChildAlreadyPresentError, - vds.set, - index, we, "key2", "name2", "write2", "read2") - self.failUnlessRaises(BadWriteEnablerError, vds.set, index, "not the write enabler",