Fix issue where deleting jobs with a shared project would erase all project files

This commit is contained in:
Brett Williams
2023-06-04 12:19:47 -05:00
parent 54ec4e7838
commit 0ba89553ab
2 changed files with 10 additions and 6 deletions

View File

@@ -433,7 +433,7 @@ def delete_job(job_id):
# Check if we can remove the 'output' directory # Check if we can remove the 'output' directory
found_job = RenderQueue.job_with_id(job_id) 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): if server.config['UPLOAD_FOLDER'] in output_dir and os.path.exists(output_dir):
shutil.rmtree(output_dir) shutil.rmtree(output_dir)
@@ -446,10 +446,14 @@ def delete_job(job_id):
if os.path.exists(thumb_path): if os.path.exists(thumb_path):
os.remove(thumb_path) os.remove(thumb_path)
# See if we own the input file (i.e. was it uploaded) # See if we own the project_dir (i.e. was it uploaded)
input_dir = os.path.dirname(found_job.input_path) project_dir = os.path.dirname(os.path.dirname(found_job.input_path))
if server.config['UPLOAD_FOLDER'] in input_dir and os.path.exists(input_dir): if server.config['UPLOAD_FOLDER'] in project_dir and os.path.exists(project_dir):
shutil.rmtree(input_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) RenderQueue.delete_job(found_job)
if request.args.get('redirect', False): if request.args.get('redirect', False):

View File

@@ -41,7 +41,7 @@ class RenderServerProxy:
if req.ok and req.status_code == 200: if req.ok and req.status_code == 200:
return req.json() return req.json()
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
logger.error(f"JSON decode error: {e}") logger.debug(f"JSON decode error: {e}")
except requests.ConnectionError as e: except requests.ConnectionError as e:
logger.error(f"Connection error: {e}") logger.error(f"Connection error: {e}")
except Exception as e: except Exception as e: