]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
storage: remove the leftover incoming/XYZ/ directory when we're done with it
authorBrian Warner <warner@lothar.com>
Sat, 15 Sep 2007 21:34:04 +0000 (14:34 -0700)
committerBrian Warner <warner@lothar.com>
Sat, 15 Sep 2007 21:34:04 +0000 (14:34 -0700)
src/allmydata/storage.py
src/allmydata/test/test_storage.py

index a185c64c70287731a094e45a6ed51ff1b17bb413..afd6e07bbe8c268f6ffad35d5a590521d16c3e1b 100644 (file)
@@ -195,6 +195,12 @@ class BucketWriter(Referenceable):
         filelen = os.stat(self.finalhome)[stat.ST_SIZE]
         self.ss.bucket_writer_closed(self, filelen)
 
+        # if we were the last share to be moved, remove the incoming/
+        # directory that was our parent
+        parentdir = os.path.split(self.incominghome)[0]
+        if not os.listdir(parentdir):
+            os.rmdir(parentdir)
+
 
 class BucketReader(Referenceable):
     implements(RIBucketReader)
index c9b4d30ed5d72d1d243175b39bb578dcc02a277d..61948c7e01728cb383368b569a5ee8311cdc1c19 100644 (file)
@@ -202,6 +202,17 @@ class Server(unittest.TestCase):
                                           renew_secret, cancel_secret,
                                           sharenums, size, Referenceable())
 
+    def test_remove_incoming(self):
+        ss = self.create("test_remove_incoming")
+        already, writers = self.allocate(ss, "vid", range(3), 10)
+        for i,wb in writers.items():
+            wb.remote_write(0, "%10d" % i)
+            wb.remote_close()
+        incomingdir = os.path.join(self.workdir("test_remove_incoming"),
+                                   "shares", "incoming")
+        leftover_dirs = os.listdir(incomingdir)
+        self.failUnlessEqual(leftover_dirs, [])
+
     def test_allocate(self):
         ss = self.create("test_allocate")