From 2dc1b98ec818d62e9992cf75bb25ab7b0bef2d6e Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Fri, 15 Nov 2024 16:56:11 +0100 Subject: [PATCH] Implemented safe save feature so that existing file is not replaced, possibly leading to loss of flagging information. --- data_flagging_utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/data_flagging_utils.py b/data_flagging_utils.py index bb78eac..469c785 100644 --- a/data_flagging_utils.py +++ b/data_flagging_utils.py @@ -31,9 +31,14 @@ def save_file(name, content): content_type, content_string = content.split(',') decoded = base64.b64decode(content_string) file_path = os.path.join(UPLOAD_DIRECTORY, name) - with open(file_path, "wb") as f: - f.write(decoded) - return file_path + if not os.path.exists(file_path): + with open(file_path, "wb") as f: + f.write(decoded) + print(f"File saved successfully at {file_path}") + return file_path + else: + print(f'File already exists at {file_path}.\nTo maintain the integrity of the existing file, it will not be overwritten.') + return file_path def filter_flags_by_label(flags_dict, label): """