diff options
Diffstat (limited to 'mullvad-daemon/src')
| -rw-r--r-- | mullvad-daemon/src/account_history.rs | 8 | ||||
| -rw-r--r-- | mullvad-daemon/src/settings.rs | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/mullvad-daemon/src/account_history.rs b/mullvad-daemon/src/account_history.rs index 016d2fd780..ab6797a6fa 100644 --- a/mullvad-daemon/src/account_history.rs +++ b/mullvad-daemon/src/account_history.rs @@ -94,11 +94,15 @@ impl AccountHistory { /// Serializes the account history and saves it to the file it was loaded from. fn save(&self) -> Result<()> { debug!("Writing account history to {}", self.cache_path.display()); - let file = File::create(&self.cache_path) + let mut file = File::create(&self.cache_path) .map(io::BufWriter::new) .chain_err(|| ErrorKind::WriteError(self.cache_path.clone()))?; - serde_json::to_writer_pretty(file, self) + serde_json::to_writer_pretty(&mut file, self) + .chain_err(|| ErrorKind::WriteError(self.cache_path.clone()))?; + + file.get_mut() + .sync_all() .chain_err(|| ErrorKind::WriteError(self.cache_path.clone())) } } diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs index 0ff007cce8..4622db15ce 100644 --- a/mullvad-daemon/src/settings.rs +++ b/mullvad-daemon/src/settings.rs @@ -81,9 +81,11 @@ impl Settings { let path = Self::get_settings_path()?; debug!("Writing settings to {}", path.display()); - let file = File::create(&path).chain_err(|| ErrorKind::WriteError(path.clone()))?; + let mut file = File::create(&path).chain_err(|| ErrorKind::WriteError(path.clone()))?; - serde_json::to_writer_pretty(file, self).chain_err(|| ErrorKind::WriteError(path)) + serde_json::to_writer_pretty(&mut file, self) + .chain_err(|| ErrorKind::WriteError(path.clone()))?; + file.sync_all().chain_err(|| ErrorKind::WriteError(path)) } fn get_settings_path() -> Result<PathBuf> { |
