[node-patches] Change in ovirt-node[master]: utils_fs: cleanup empty dirs on unpersist
asegurap at redhat.com
asegurap at redhat.com
Thu Jul 3 20:43:59 UTC 2014
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: utils_fs: cleanup empty dirs on unpersist
......................................................................
utils_fs: cleanup empty dirs on unpersist
Up until now, when unpersisting a path like:
/config/var/run/vdsm/persistence/foo
in /config there would be remains stored forever:
/config/var/run/vdsm/persistence
With this patch, the parent directory of the persisted path will be
iteratively cleaned upwards so that empty directories are pruned
from /config
Change-Id: I0431974804819c5d4f587165cae7be665529b345
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M src/ovirt/node/utils/fs/__init__.py
1 file changed, 18 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/72/29572/1
diff --git a/src/ovirt/node/utils/fs/__init__.py b/src/ovirt/node/utils/fs/__init__.py
index 10dca29..a660dd2 100644
--- a/src/ovirt/node/utils/fs/__init__.py
+++ b/src/ovirt/node/utils/fs/__init__.py
@@ -539,6 +539,21 @@
exc_info=True)
return -1
+ def _cleanup_tree(self, dirpath):
+ """Removes empty directories in the structure. abspath must be a dir"""
+ path = dirpath
+ while True:
+ try:
+ os.rmdir(path)
+ except OSError as ose:
+ if ose.errno == errno.ENOTEMPTY:
+ self._logger.debug('Cleaned up "%s" all the way up to '
+ '(not including) "%s"', dirpath, path)
+ break
+ else:
+ raise
+ path = os.path.dirname(path)
+
def _unpersist_dir(self, abspath):
"""Remove the persistent version of a directory and refresh the version
in the live filesystem with what was persisted"""
@@ -554,6 +569,7 @@
shutil.copytree(persisted_path, abspath, symlinks=True)
shutil.rmtree(persisted_path)
self._del_path_entry(abspath)
+ self._cleanup_tree(os.path.dirname(persisted_path))
self._logger.info('Successfully unpersisted directory "%s"', abspath)
def _unpersist_file(self, abspath):
@@ -568,6 +584,7 @@
shutil.copy2(persisted_path, abspath)
os.unlink(persisted_path)
self._del_path_entry(abspath)
+ self._cleanup_tree(os.path.dirname(persisted_path))
self._logger.info('Successfully unpersisted file "%s"', abspath)
def _unpersist_symlink(self, abspath):
@@ -587,6 +604,7 @@
os.symlink(stored_target, abspath)
os.unlink(persisted_path)
self._del_path_entry(abspath)
+ self._cleanup_tree(os.path.dirname(persisted_path))
self._logger.info('Successfully unpersisted symlink "%s"', abspath)
def delete(self, filename):
--
To view, visit http://gerrit.ovirt.org/29572
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0431974804819c5d4f587165cae7be665529b345
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>
More information about the node-patches
mailing list