]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
dirnode: change the defined behavior of RIVirtualDriveServer.set to allow replace...
authorBrian Warner <warner@allmydata.com>
Fri, 17 Aug 2007 00:03:19 +0000 (17:03 -0700)
committerBrian Warner <warner@allmydata.com>
Fri, 17 Aug 2007 00:03:19 +0000 (17:03 -0700)
src/allmydata/dirnode.py
src/allmydata/interfaces.py
src/allmydata/test/test_dirnode.py

index b3d6d8261d72483dbffc5e8bdf23a465b41f51f4..bdbea6abb0def791f0fbe4d028d171a73a4e54f9 100644 (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)
index b8369d471ff3e5680fab260277588fc84b7974dd..785b74774fa1f0803994a60bd7402cfa0635ef62 100644 (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."""
index 47e1eb5d9c44eda595dfac52aad0ce26e3b7d814..fb753f3afe2098e1d8add9a111b7fe06300df8ae 100644 (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",