forked from p15670423/monkey
Break PBA file deletion into functions: attempt to delete PBA file in another function
This commit is contained in:
parent
4854c9cfc9
commit
4f94e9de74
|
@ -18,7 +18,7 @@ from monkey_island.cc.services.post_breach_files import (
|
||||||
__author__ = "VakarisZ"
|
__author__ = "VakarisZ"
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
# Front end uses these strings to identify which files to work with (linux of windows)
|
# Front end uses these strings to identify which files to work with (linux or windows)
|
||||||
LINUX_PBA_TYPE = "PBAlinux"
|
LINUX_PBA_TYPE = "PBAlinux"
|
||||||
WINDOWS_PBA_TYPE = "PBAwindows"
|
WINDOWS_PBA_TYPE = "PBAwindows"
|
||||||
|
|
||||||
|
@ -71,12 +71,8 @@ class FileUpload(flask_restful.Resource):
|
||||||
filename = ConfigService.get_config_value(filename_path)
|
filename = ConfigService.get_config_value(filename_path)
|
||||||
if filename:
|
if filename:
|
||||||
file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename)
|
file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename)
|
||||||
try:
|
FileUpload._delete_file(file_path)
|
||||||
if os.path.exists(file_path):
|
ConfigService.set_config_value(filename_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 {}
|
return {}
|
||||||
|
|
||||||
|
@ -97,3 +93,11 @@ class FileUpload(flask_restful.Resource):
|
||||||
(PBA_LINUX_FILENAME_PATH if is_linux else PBA_WINDOWS_FILENAME_PATH), filename
|
(PBA_LINUX_FILENAME_PATH if is_linux else PBA_WINDOWS_FILENAME_PATH), filename
|
||||||
)
|
)
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _delete_file(file_path):
|
||||||
|
try:
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
os.remove(file_path)
|
||||||
|
except OSError as e:
|
||||||
|
LOG.error("Couldn't remove previously uploaded post breach files: %s" % e)
|
||||||
|
|
Loading…
Reference in New Issue