From 80234c56007d796d061015eb13727332e793a085 Mon Sep 17 00:00:00 2001 From: Gabe Muniz Date: Mon, 16 Mar 2020 19:54:15 +0000 Subject: [PATCH] rework the tar to always delete the leftover directories --- awx/main/analytics/core.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/awx/main/analytics/core.py b/awx/main/analytics/core.py index 143465ae10..3ff61b82f9 100644 --- a/awx/main/analytics/core.py +++ b/awx/main/analytics/core.py @@ -134,13 +134,17 @@ def gather(dest=None, module=None, collection_type='scheduled'): settings.SYSTEM_UUID, run_now.strftime('%Y-%m-%d-%H%M%S%z') ]) - tgz = shutil.make_archive( - os.path.join(os.path.dirname(dest), tarname), - 'gztar', - dest - ) - shutil.rmtree(dest) - return tgz + try: + tgz = shutil.make_archive( + os.path.join(os.path.dirname(dest), tarname), + 'gztar', + dest + ) + return tgz + except Exception: + logger.exception("Failed to write analytics archive file") + finally: + shutil.rmtree(dest) def ship(path):