components/openstack/cinder/patches/11-nfs-backup.patch
changeset 5405 66fd59fecd68
child 6849 f9a2279efa0d
equal deleted inserted replaced
5404:55e409ba4e72 5405:66fd59fecd68
       
     1 In-house patch to cleanup backup container directories when empty.
       
     2 
       
     3 Patch may be suitable for pushing upsteam.
       
     4 
       
     5 --- cinder-2015.1.0/cinder/backup/drivers/nfs.py.orig	2015-11-24 11:49:37.670852276 -0700
       
     6 +++ cinder-2015.1.0/cinder/backup/drivers/nfs.py	2015-11-24 13:31:57.282595085 -0700
       
     7 @@ -137,9 +137,21 @@ class NFSBackupDriver(chunkeddriver.Chun
       
     8          return open(path, 'r')
       
     9  
       
    10      def delete_object(self, container, object_name):
       
    11 -        # TODO(tbarron):  clean up the container path if it is empty
       
    12 -        path = os.path.join(self.backup_path, container, object_name)
       
    13 -        os.remove(path)
       
    14 +        obj_path = os.path.join(self.backup_path, container, object_name)
       
    15 +        cpath = os.path.join(self.backup_path, container)
       
    16 +        os.remove(obj_path)
       
    17 +
       
    18 +        # Cleanup container path if it is empty.
       
    19 +        if not os.listdir(cpath):
       
    20 +            start = os.getcwd()
       
    21 +            os.chdir(self.backup_path)
       
    22 +            try:
       
    23 +                # Try to remove all the component dirs
       
    24 +                # in container path.  os.removedirs will
       
    25 +                # stop if the directory is not empty.
       
    26 +                os.removedirs(container)
       
    27 +            finally:
       
    28 +                os.chdir(start)
       
    29  
       
    30      def _generate_object_name_prefix(self, backup):
       
    31          return 'backup'