From 23a8def0d8c050a684db2b955e0d0c1017f87d63 Mon Sep 17 00:00:00 2001 From: Qingmin Duanmu Date: Thu, 8 Dec 2022 12:14:58 +0800 Subject: [PATCH] Retry deleting with onerror handler --- openlcsd/flow/task_wrapper.py | 9 +++------ openlcsd/flow/tasks.py | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/openlcsd/flow/task_wrapper.py b/openlcsd/flow/task_wrapper.py index 64514585..d85ceeff 100644 --- a/openlcsd/flow/task_wrapper.py +++ b/openlcsd/flow/task_wrapper.py @@ -1,6 +1,6 @@ import celery import os -import shutil +from commoncode.fileutils import delete class WorkflowWrapperTask(celery.Task): @@ -14,17 +14,14 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo): if comp_type != 'OCI' or args[0].get('parent'): src_dest_dir = args[0].get('src_dest_dir') if src_dest_dir and os.path.exists(src_dest_dir): - shutil.rmtree(src_dest_dir, ignore_errors=True) + delete(src_dest_dir) # Only keep the source tarball for failed container components if status == 'FAILURE' and 'src_dir' in args[0]: pass else: tmp_src_filepath = args[0].get('tmp_src_filepath') if tmp_src_filepath and os.path.exists(tmp_src_filepath): - if os.path.isdir(tmp_src_filepath): - shutil.rmtree(tmp_src_filepath, ignore_errors=True) - else: - os.remove(tmp_src_filepath) + delete(tmp_src_filepath) super().after_return( status, retval, task_id, args, kwargs, einfo) diff --git a/openlcsd/flow/tasks.py b/openlcsd/flow/tasks.py index c2c3903d..cf3bae82 100644 --- a/openlcsd/flow/tasks.py +++ b/openlcsd/flow/tasks.py @@ -8,6 +8,7 @@ from requests.exceptions import HTTPError from checksumdir import dirhash +from commoncode.fileutils import delete from workflow.patterns.controlflow import IF from workflow.patterns.controlflow import IF_ELSE from packagedcode.rpm import parse as rpm_parse @@ -512,7 +513,7 @@ def prepare_dest_dir(context, engine): src_dir = tempfile.mkdtemp( prefix='src_', dir=context.get('tmp_root_dir')) if os.path.exists(src_dir): - shutil.rmtree(src_dir, ignore_errors=True) + delete(src_dir) try: os.makedirs(src_dir) except OSError as err: