diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-15 22:06:45 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-22 13:46:50 +0000 |
| commit | 432564d3f3b6e80a8d7bbc44ddebdc7e8fe452a6 (patch) | |
| tree | 8b35a3bb0e28bbf6002acf1570ee50239a4273d6 | |
| parent | ff43c691b30a4e597e5e4103d1e6a3dae7b67698 (diff) | |
| download | mullvadvpn-432564d3f3b6e80a8d7bbc44ddebdc7e8fe452a6.tar.xz mullvadvpn-432564d3f3b6e80a8d7bbc44ddebdc7e8fe452a6.zip | |
Create `load_settings_from_file()` method
| -rw-r--r-- | mullvad-daemon/src/settings.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs index 18a61ec690..f0c9a82404 100644 --- a/mullvad-daemon/src/settings.rs +++ b/mullvad-daemon/src/settings.rs @@ -1,15 +1,18 @@ use log::info; -use std::ops::{Deref, DerefMut}; +use mullvad_types::settings::Settings; +use std::{ + io, + ops::{Deref, DerefMut}, +}; #[cfg(windows)] use { log::{error, warn}, - mullvad_types::settings::Error as SettingsError, std::io::ErrorKind, talpid_core::logging::windows::log_sink, }; -pub use mullvad_types::settings::*; +pub use mullvad_types::settings::Error; #[derive(Debug)] pub struct SettingsPersister { @@ -18,7 +21,7 @@ pub struct SettingsPersister { impl SettingsPersister { pub fn load() -> Self { - let settings = match Settings::load() { + let settings = match Self::load_settings_from_file() { Ok(mut settings) => { // Force IPv6 to be enabled on Android if cfg!(target_os = "android") { @@ -27,7 +30,7 @@ impl SettingsPersister { settings } #[cfg(windows)] - Err(SettingsError::ReadError(ref _path, ref e)) if e.kind() == ErrorKind::NotFound => { + Err(error) if error.kind() == ErrorKind::NotFound => { if Self::migrate_after_windows_update() { match Settings::load() { Ok(settings) => { @@ -79,6 +82,13 @@ impl SettingsPersister { } } + fn load_settings_from_file() -> Result<Settings, io::Error> { + Settings::load().map_err(|error| match error { + Error::ReadError(_, io_error) => io_error, + _ => io::Error::new(io::ErrorKind::Other, "Failed to load settings"), + }) + } + pub fn to_settings(&self) -> Settings { self.settings.clone() } |
