forked from p34709852/monkey
island: Consolidate duplicate delete post breach file functionality
This commit is contained in:
parent
71029cb7f9
commit
5742e85ff5
|
@ -1,6 +1,5 @@
|
|||
import copy
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import flask_restful
|
||||
|
@ -84,16 +83,7 @@ class FileUpload(flask_restful.Resource):
|
|||
)
|
||||
filename = ConfigService.get_config_value(filename_path)
|
||||
if filename:
|
||||
file_path = Path(PostBreachFilesService.get_custom_pba_directory()).joinpath(filename)
|
||||
FileUpload._delete_file(file_path)
|
||||
PostBreachFilesService.remove_file(filename)
|
||||
ConfigService.set_config_value(filename_path, "")
|
||||
|
||||
return {}
|
||||
|
||||
@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)
|
||||
|
|
|
@ -36,12 +36,12 @@ class PostBreachFilesService:
|
|||
PBA_LINUX_FILENAME_PATH
|
||||
)
|
||||
if linux_filename:
|
||||
PostBreachFilesService._remove_file(linux_filename)
|
||||
PostBreachFilesService.remove_file(linux_filename)
|
||||
if windows_filename:
|
||||
PostBreachFilesService._remove_file(windows_filename)
|
||||
PostBreachFilesService.remove_file(windows_filename)
|
||||
|
||||
@staticmethod
|
||||
def _remove_file(file_name):
|
||||
def remove_file(file_name):
|
||||
file_path = os.path.join(PostBreachFilesService.get_custom_pba_directory(), file_name)
|
||||
try:
|
||||
if os.path.exists(file_path):
|
||||
|
|
Loading…
Reference in New Issue