dirnode: change the defined behavior of RIVirtualDriveServer.set to allow replace-in-place without raising an exception

This commit is contained in:
Brian Warner 2007-08-16 17:03:19 -07:00
parent be0ab3b1f1
commit fe06b3be8b
3 changed files with 14 additions and 14 deletions

View File

@ -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)

View File

@ -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."""

View File

@ -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",