From c6ddbf4505f4d13d4748d6f3577e898f485b9071 Mon Sep 17 00:00:00 2001 From: Markus Binsteiner Date: Wed, 17 Apr 2024 14:37:31 +0200 Subject: [PATCH] chore: cleanup temp files --- src/kiara_plugin/onboarding/modules/download/__init__.py | 6 +++++- src/kiara_plugin/onboarding/utils/download.py | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/kiara_plugin/onboarding/modules/download/__init__.py b/src/kiara_plugin/onboarding/modules/download/__init__.py index 56e811c..f237b7d 100644 --- a/src/kiara_plugin/onboarding/modules/download/__init__.py +++ b/src/kiara_plugin/onboarding/modules/download/__init__.py @@ -90,8 +90,12 @@ def retrieve_archive( suffix = "" tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix) - atexit.register(tmp_file.close) + def rm_tmp_file(): + tmp_file.close() + os.unlink(tmp_file.name) + + atexit.register(rm_tmp_file) kiara_file: KiaraFile kiara_file = download_file( # type: ignore diff --git a/src/kiara_plugin/onboarding/utils/download.py b/src/kiara_plugin/onboarding/utils/download.py index bb3fcaa..d8c2967 100644 --- a/src/kiara_plugin/onboarding/utils/download.py +++ b/src/kiara_plugin/onboarding/utils/download.py @@ -145,10 +145,15 @@ def download_file_bundle( suffix = "" tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix) - atexit.register(tmp_file.close) + + def rm_tmp_file(): + tmp_file.close() + os.unlink(tmp_file.name) + + atexit.register(rm_tmp_file) history = [] - datetime.utcnow().replace(tzinfo=pytz.utc) + # datetime.utcnow().replace(tzinfo=pytz.utc) with open(tmp_file.name, "wb") as f: with httpx.stream("GET", url, follow_redirects=True) as r: history.append(dict(r.headers))