summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-07-18 14:07:38 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-07-18 15:00:49 +0200
commitd165d9abd8f9ee13992f02ed9d25e237ea1be2ac (patch)
treed2c945a9deafca270dabde439f8bc314ec1c435a
parent6a117eff8ef04296f8e765ea2953dddb9468095c (diff)
downloadmullvadvpn-d165d9abd8f9ee13992f02ed9d25e237ea1be2ac.tar.xz
mullvadvpn-d165d9abd8f9ee13992f02ed9d25e237ea1be2ac.zip
Save settings in setter methods
-rw-r--r--mullvad-daemon/src/main.rs8
-rw-r--r--mullvad-daemon/src/settings.rs8
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(())
}
}