Transitioned Delete functionality to the model's data service (away from the model itself). And setup destroy service to be run as a background thread, which means disable separately
This commit is contained in:
parent
788c9f8cc4
commit
ffd1080d03
5 changed files with 28 additions and 7 deletions
|
|
@ -92,7 +92,9 @@ class ProfileController:
|
|||
profile_id = profile.id
|
||||
|
||||
# 2. Permanently delete from disk
|
||||
profile.delete()
|
||||
removed = model_manipulator.delete(profile)
|
||||
if not removed.valid:
|
||||
return removed.wrap("Unable to delete files, so keeping repo intact.")
|
||||
|
||||
# 3. update cache with the temp variable to prevent drift
|
||||
ProfileController._repo.invalidate(profile_id=profile_id)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# utils
|
||||
from core.errors.logger import logger
|
||||
from core.models.Result import Result, ResultError
|
||||
from core.services.networking.systemwide.general_tools.manage_sudo_configs import remove_sudo_config
|
||||
from core.services.config_tools.manage_sudo_configs import remove_sudo_config
|
||||
|
||||
from core.controllers.ProfileController import ProfileController
|
||||
from core.models.BaseProfile import BaseProfile as Profile
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
from core.models.enum_models import ProtocolChoice
|
||||
from core.utils.run_commands import run_generic_command
|
||||
from core.models.Result import Result
|
||||
from core.models.system.SystemProfile import SystemProfile
|
||||
from core.utils.basic_operations.does_file_exist import does_file_exist
|
||||
|
||||
def get_target_filename(profile: SystemProfile) -> str:
|
||||
if profile.connection.code == "wireguard":
|
||||
if profile.protocol == ProtocolChoice.WIREGUARD:
|
||||
return "wg.conf"
|
||||
else:
|
||||
return "proxy.json"
|
||||
|
|
@ -14,8 +16,10 @@ def remove_sudo_config(profile: SystemProfile) -> Result:
|
|||
file_name = get_target_filename(profile)
|
||||
sudo_filepath = f"{base_folder}/{file_name}"
|
||||
|
||||
if not does_file_exist(sudo_filepath):
|
||||
return Result(valid=True, message="Sudo config is already gone, so it doesn't need to be deleted.")
|
||||
|
||||
# REMOVE:
|
||||
command = ['pkexec', 'rm', '-f', sudo_filepath]
|
||||
human_readable_goal = "Removing file from sudo folder"
|
||||
return run_generic_command(command, human_readable_goal, timeout=35)
|
||||
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
from core.services.config_tools.manage_sudo_configs import remove_sudo_config
|
||||
from core.models.session.SessionProfile import SessionProfile
|
||||
from core.models.orm_calls.location_calls import LocationCache
|
||||
from core.models.BaseProfile import BaseProfile as Profile
|
||||
|
|
@ -292,3 +293,17 @@ def save_to_disk(profile: Profile):
|
|||
config_file_path = f'{profile_config_path}/config.json'
|
||||
write_atomically(config_file_path, config_file_contents)
|
||||
|
||||
|
||||
def delete(profile: Profile) -> Result:
|
||||
"""Delete the files on disk for a given profile."""
|
||||
|
||||
logger.info(f"Deleting profile {profile.name} id {profile.id}")
|
||||
|
||||
if profile.type == ProfileType.SYSTEM:
|
||||
removed = remove_sudo_config(profile)
|
||||
if not removed.valid:
|
||||
return removed.wrap("Unable to delete the systemwide configs behind sudo protection.")
|
||||
|
||||
shutil.rmtree(get_config_path(profile.id), ignore_errors=True)
|
||||
shutil.rmtree(get_data_path(profile.id), ignore_errors=True)
|
||||
return Result(valid=True)
|
||||
|
|
@ -361,10 +361,10 @@ def destroy_profile(
|
|||
####################################
|
||||
# DESTROY PROFILE
|
||||
####################################
|
||||
logger.info("Disabling profile")
|
||||
disable_profile(profile)
|
||||
# logger.info("Disabling profile")
|
||||
# disable_profile(profile)
|
||||
|
||||
logger.info("Wiping profile from disk..")
|
||||
logger.info("Wiping profile from disk and cache..")
|
||||
ProfileController.delete(profile)
|
||||
|
||||
if profile_observer is not None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue