summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src
diff options
context:
space:
mode:
authorEmīls <emils@mullvad.net>2018-06-23 00:41:25 +0100
committerEmīls Piņķis <emils@mullvad.net>2018-06-25 13:31:29 +0100
commitc8b23df372a2f7846b87d0733f8d047f8903bb4a (patch)
treec5f1fa8705025e2e27030f29c1ed78f9cc2d3ff8 /mullvad-daemon/src
parent1d70f24f6a7fcb10d9ced9592a279ec8ee3c1592 (diff)
downloadmullvadvpn-c8b23df372a2f7846b87d0733f8d047f8903bb4a.tar.xz
mullvadvpn-c8b23df372a2f7846b87d0733f8d047f8903bb4a.zip
Flush file writes when saving config and backup files
Diffstat (limited to 'mullvad-daemon/src')
-rw-r--r--mullvad-daemon/src/account_history.rs8
-rw-r--r--mullvad-daemon/src/settings.rs6
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> {