diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-16 00:48:11 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-22 13:46:50 +0000 |
| commit | b37e4c4b7f9b92ce787e474246592285cf4a56be (patch) | |
| tree | d51182c5e5094022e58f19d64d57e6e4e7f3544c | |
| parent | 94d9eca913409b4d7405b15116df4289c5a852b1 (diff) | |
| download | mullvadvpn-b37e4c4b7f9b92ce787e474246592285cf4a56be.tar.xz mullvadvpn-b37e4c4b7f9b92ce787e474246592285cf4a56be.zip | |
Move `reset` method to `SettingsPersister`
| -rw-r--r-- | mullvad-daemon/src/settings.rs | 20 | ||||
| -rw-r--r-- | mullvad-types/src/settings/mod.rs | 30 |
2 files changed, 21 insertions, 29 deletions
diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs index 622582becf..51482de537 100644 --- a/mullvad-daemon/src/settings.rs +++ b/mullvad-daemon/src/settings.rs @@ -10,6 +10,9 @@ use std::{ }; use talpid_types::ErrorExt; +#[cfg(not(target_os = "android"))] +use {std::fs, talpid_types::ErrorExt}; + #[cfg(windows)] use { log::{error, warn}, @@ -19,6 +22,10 @@ use { #[derive(err_derive::Error, Debug)] pub enum Error { + #[error(display = "Unable to remove settings file {}", _0)] + #[cfg(not(target_os = "android"))] + DeleteError(String, #[error(source)] io::Error), + #[error(display = "Settings operation failed")] SettingsError(#[error(source)] mullvad_types::settings::Error), } @@ -133,7 +140,18 @@ impl SettingsPersister { /// Resets default settings #[cfg(not(target_os = "android"))] pub fn reset(&mut self) -> Result<(), Error> { - self.settings.reset() + self.settings = Settings::default(); + self.settings.save().or_else(|e| { + log::error!( + "{}", + e.display_chain_with_msg("Unable to save default settings") + ); + log::error!("Will attempt to remove settings file"); + Settings::get_settings_path().and_then(|path| { + fs::remove_file(&path) + .map_err(|e| Error::DeleteError(path.display().to_string(), e)) + }) + }) } pub fn to_settings(&self) -> Settings { diff --git a/mullvad-types/src/settings/mod.rs b/mullvad-types/src/settings/mod.rs index aed83329e1..6b5ae102cc 100644 --- a/mullvad-types/src/settings/mod.rs +++ b/mullvad-types/src/settings/mod.rs @@ -7,15 +7,8 @@ use jnix::IntoJava; use log::{debug, info}; use serde::{Deserialize, Serialize}; use serde_json; -use std::{ - fs::{self, File}, - io, - path::PathBuf, -}; -use talpid_types::{ - net::{openvpn, wireguard, GenericTunnelOptions}, - ErrorExt, -}; +use std::{fs::File, io, path::PathBuf}; +use talpid_types::net::{openvpn, wireguard, GenericTunnelOptions}; mod migrations; @@ -27,9 +20,6 @@ pub enum Error { #[error(display = "Unable to create settings directory")] DirectoryError(#[error(source)] mullvad_paths::Error), - #[error(display = "Unable to remove settings file {}", _0)] - DeleteError(String, #[error(source)] io::Error), - #[error(display = "Malformed settings")] ParseError(#[error(source)] serde_json::Error), @@ -120,22 +110,6 @@ impl Settings { .map_err(|e| Error::WriteError(path.display().to_string(), e)) } - /// Resets default settings - pub fn reset(&mut self) -> Result<()> { - *self = Default::default(); - self.save().or_else(|e| { - log::error!( - "{}", - e.display_chain_with_msg("Unable to save default settings") - ); - log::error!("Will attempt to remove settings file"); - Self::get_settings_path().and_then(|path| { - fs::remove_file(&path) - .map_err(|e| Error::DeleteError(path.display().to_string(), e)) - }) - }) - } - pub fn get_settings_path() -> Result<PathBuf> { let dir = ::mullvad_paths::settings_dir().map_err(Error::DirectoryError)?; Ok(dir.join(SETTINGS_FILE)) |
