class BadWriteEnablerError(Exception):
pass
-class ChildAlreadyPresentError(Exception):
- pass
class NoPublicRootError(Exception):
pass
# 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)
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):
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() ).
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."""
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
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",