From 0ba89553ab06bd6e7eeedfc49c62b36ebb69ac9e Mon Sep 17 00:00:00 2001 From: Brett Williams Date: Sun, 4 Jun 2023 12:19:47 -0500 Subject: [PATCH] Fix issue where deleting jobs with a shared project would erase all project files --- lib/server/job_server.py | 14 +++++++++----- lib/server/server_proxy.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/server/job_server.py b/lib/server/job_server.py index 8290df8..d99d7bb 100755 --- a/lib/server/job_server.py +++ b/lib/server/job_server.py @@ -433,7 +433,7 @@ def delete_job(job_id): # Check if we can remove the 'output' directory found_job = RenderQueue.job_with_id(job_id) - output_dir = os.path.dirname(os.path.dirname(found_job.output_path)) + output_dir = os.path.dirname(found_job.output_path) if server.config['UPLOAD_FOLDER'] in output_dir and os.path.exists(output_dir): shutil.rmtree(output_dir) @@ -446,10 +446,14 @@ def delete_job(job_id): if os.path.exists(thumb_path): os.remove(thumb_path) - # See if we own the input file (i.e. was it uploaded) - input_dir = os.path.dirname(found_job.input_path) - if server.config['UPLOAD_FOLDER'] in input_dir and os.path.exists(input_dir): - shutil.rmtree(input_dir) + # See if we own the project_dir (i.e. was it uploaded) + project_dir = os.path.dirname(os.path.dirname(found_job.input_path)) + if server.config['UPLOAD_FOLDER'] in project_dir and os.path.exists(project_dir): + # check to see if any other projects are sharing the same project file + project_dir_files = [f for f in os.listdir(project_dir) if not f.startswith('.')] + if len(project_dir_files) == 0 or (len(project_dir_files) == 1 and 'source' in project_dir_files[0]): + logger.info(f"Removing project directory: {project_dir}") + shutil.rmtree(project_dir) RenderQueue.delete_job(found_job) if request.args.get('redirect', False): diff --git a/lib/server/server_proxy.py b/lib/server/server_proxy.py index dcecfcb..4969444 100644 --- a/lib/server/server_proxy.py +++ b/lib/server/server_proxy.py @@ -41,7 +41,7 @@ class RenderServerProxy: if req.ok and req.status_code == 200: return req.json() except json.JSONDecodeError as e: - logger.error(f"JSON decode error: {e}") + logger.debug(f"JSON decode error: {e}") except requests.ConnectionError as e: logger.error(f"Connection error: {e}") except Exception as e: