From 469d2a4eeddf51270bff2db038bc35b27717eee2 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 3 Dec 2022 13:59:23 -0500 Subject: [PATCH] Delete persistent settings files when persistence disabled; fix #55 --- backend/src/api/handler.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/src/api/handler.rs b/backend/src/api/handler.rs index 49067ba..bf31495 100644 --- a/backend/src/api/handler.rs +++ b/backend/src/api/handler.rs @@ -161,15 +161,23 @@ impl ApiMessageHandler { // save log::debug!("api_worker is saving..."); let is_persistent = *settings.general.persistent(); + let save_path = crate::utility::settings_dir() + .join(settings.general.get_path().clone()); if is_persistent { - let save_path = crate::utility::settings_dir() - .join(settings.general.get_path().clone()); let settings_clone = settings.json(); let save_json: SettingsJson = settings_clone.into(); unwrap_maybe_fatal(save_json.save(&save_path), "Failed to save settings"); log::debug!("Saved settings to {}", save_path.display()); } else { - log::debug!("Ignored save request for non-persistent settings"); + if save_path.exists() { + if let Err(e) = std::fs::remove_file(&save_path) { + log::warn!("Failed to delete persistent settings file {}: {}", save_path.display(), e); + } else { + log::debug!("Deleted persistent settings file {}", save_path.display()); + } + } else { + log::debug!("Ignored save request for non-persistent settings"); + } } } }