From 38ecb595193c01835027f521b691eeeaedb357d4 Mon Sep 17 00:00:00 2001 From: Joel Mathew Thomas <90510078+joelmathewthomas@users.noreply.github.com> Date: Fri, 21 Mar 2025 01:36:38 +0530 Subject: [PATCH] bugfix: fix celery crashing, due to UPLOAD_DIR being deleted Delete all dirs and files inside UPLOAD_DIR instead --- api/api/views.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/api/views.py b/api/api/views.py index 6cb298c..7769ac5 100644 --- a/api/api/views.py +++ b/api/api/views.py @@ -19,9 +19,16 @@ from freqsplit.input.format_checker import is_supported_format UPLOAD_DIR = "/tmp/freqsplit" # Ensure the temp directory exists -shutil.rmtree(UPLOAD_DIR) os.makedirs(UPLOAD_DIR, exist_ok=True) +# Remove all files inside the directory +for filename in os.listdir(UPLOAD_DIR): + file_path = os.path.join(UPLOAD_DIR, filename) + if os.path.isfile(file_path) or os.path.islink(file_path): + os.unlink(file_path) + elif os.path.isdir(file_path): + shutil.rmtree(file_path) + # Endpoint to ping server @api_view(['GET']) def ping(request):