In-house patch to cleanup backup container directories when empty.
Patch may be suitable for pushing upsteam.
--- cinder-8.0.0/cinder/backup/drivers/posix.py.~1~ 2016-04-07 00:30:48.000000000 -0700
+++ cinder-8.0.0/cinder/backup/drivers/posix.py 2016-06-10 14:44:19.856054005 -0700
@@ -122,9 +122,21 @@ class PosixBackupDriver(chunkeddriver.Ch
return open(path, 'rb')
def delete_object(self, container, object_name):
- # TODO(tbarron): clean up the container path if it is empty
- path = os.path.join(self.backup_path, container, object_name)
- os.remove(path)
+ obj_path = os.path.join(self.backup_path, container, object_name)
+ cpath = os.path.join(self.backup_path, container)
+ os.remove(obj_path)
+
+ # Cleanup container path if it is empty.
+ if not os.listdir(cpath):
+ start = os.getcwd()
+ os.chdir(self.backup_path)
+ try:
+ # Try to remove all the component dirs
+ # in container path. os.removedirs will
+ # stop if the directory is not empty.
+ os.removedirs(container)
+ finally:
+ os.chdir(start)
def _generate_object_name_prefix(self, backup):
return 'backup'