From 7cf0d60b085f29716597ce11748e290b12a7bbfc Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 1 Dec 2013 18:42:07 +0100 Subject: [PATCH] catch permissionserror when deleting old cache Signed-off-by: Nico Schottelius --- cdist/exec/local.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 3a3ac706..88b49be9 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -186,8 +186,13 @@ class Local(object): def save_cache(self): destination = os.path.join(self.cache_path, self.target_host) self.log.debug("Saving " + self.base_path + " to " + destination) - if os.path.exists(destination): - shutil.rmtree(destination) + + try: + if os.path.exists(destination): + shutil.rmtree(destination) + except PermissionError as e: + raise cdist.Error("Cannot delete old cache %s: %s" % (destination, e)) + shutil.move(self.base_path, destination) def _create_conf_path_and_link_conf_dirs(self):