From 4854c9cfc92f6c0c4dc01a425023d719a12507eb Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 25 Mar 2021 19:58:50 +0530 Subject: [PATCH] Attempt to remove custom PBA file when resetting config only if filename exists in DB --- .../monkey_island/cc/resources/pba_file_upload.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/monkey/monkey_island/cc/resources/pba_file_upload.py b/monkey/monkey_island/cc/resources/pba_file_upload.py index 16d71cfeb..5f41964cb 100644 --- a/monkey/monkey_island/cc/resources/pba_file_upload.py +++ b/monkey/monkey_island/cc/resources/pba_file_upload.py @@ -69,13 +69,14 @@ class FileUpload(flask_restful.Resource): PBA_LINUX_FILENAME_PATH if file_type == "PBAlinux" else PBA_WINDOWS_FILENAME_PATH ) filename = ConfigService.get_config_value(filename_path) - file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename) - try: - if os.path.exists(file_path): - os.remove(file_path) - ConfigService.set_config_value(filename_path, "") - except OSError as e: - LOG.error("Can't remove previously uploaded post breach files: %s" % e) + if filename: + file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename) + try: + if os.path.exists(file_path): + os.remove(file_path) + ConfigService.set_config_value(filename_path, "") + except OSError as e: + LOG.error("Can't remove previously uploaded post breach files: %s" % e) return {}