Attempt to remove custom PBA file when resetting config only if filename exists in DB

This commit is contained in:
Shreya 2021-03-25 19:58:50 +05:30
parent 8121f08aa9
commit 4854c9cfc9
1 changed files with 8 additions and 7 deletions

View File

@ -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 {}