diff options
| -rw-r--r-- | mullvad-daemon/src/main.rs | 8 | ||||
| -rw-r--r-- | mullvad-daemon/src/settings.rs | 8 |
2 files changed, 10 insertions, 6 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index bfaa1827c9..680e5dbb90 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -272,8 +272,8 @@ impl Daemon { } } SetAccount(account_token) => { - self.settings.set_account_token(account_token); - self.save_settings(); + let save_result = self.settings.set_account_token(account_token); + self.handle_settings_save(save_result); } GetAccount(tx) => { if let Err(_) = tx.send(self.settings.get_account_token()) { @@ -297,8 +297,8 @@ impl Daemon { self.set_target_state(TargetState::Unsecured) } - fn save_settings(&self) { - if let Err(e) = self.settings.save().chain_err(|| "Unable to save settings") { + fn handle_settings_save(&self, save_result: settings::Result<()>) { + if let Err(e) = save_result.chain_err(|| "Unable to save settings") { error!("{}", e.display()); } } diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs index 6aac3a5089..229ccd9709 100644 --- a/mullvad-daemon/src/settings.rs +++ b/mullvad-daemon/src/settings.rs @@ -61,7 +61,7 @@ impl Settings { } /// Serializes the settings and saves them to the file it was loaded from. - pub fn save(&self) -> Result<()> { + fn save(&self) -> Result<()> { let settings_path = Self::get_settings_path()?; let data = toml::to_string(self).chain_err(|| ErrorKind::ParseError)?; @@ -88,7 +88,8 @@ impl Settings { self.account_token.clone() } - pub fn set_account_token(&mut self, account_token: Option<String>) { + /// Changes account number to the one given. Also saves the new settings to disk. + pub fn set_account_token(&mut self, account_token: Option<String>) -> Result<()> { if account_token != self.account_token { info!( "Changing account token from {} to {}", @@ -96,6 +97,9 @@ impl Settings { Self::format_account_token(&account_token), ); self.account_token = account_token; + self.save() + } else { + Ok(()) } } |
