diff options
| author | Emīls <emils@mullvad.net> | 2018-06-23 00:41:25 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2018-06-25 13:31:29 +0100 |
| commit | c8b23df372a2f7846b87d0733f8d047f8903bb4a (patch) | |
| tree | c5f1fa8705025e2e27030f29c1ed78f9cc2d3ff8 /talpid-core | |
| parent | 1d70f24f6a7fcb10d9ced9592a279ec8ee3c1592 (diff) | |
| download | mullvadvpn-c8b23df372a2f7846b87d0733f8d047f8903bb4a.tar.xz mullvadvpn-c8b23df372a2f7846b87d0733f8d047f8903bb4a.zip | |
Flush file writes when saving config and backup files
Diffstat (limited to 'talpid-core')
| -rw-r--r-- | talpid-core/src/firewall/linux/dns.rs | 12 | ||||
| -rw-r--r-- | talpid-core/src/firewall/windows/system_state.rs | 4 |
2 files changed, 13 insertions, 3 deletions
diff --git a/talpid-core/src/firewall/linux/dns.rs b/talpid-core/src/firewall/linux/dns.rs index 9353476d56..840ffd609e 100644 --- a/talpid-core/src/firewall/linux/dns.rs +++ b/talpid-core/src/firewall/linux/dns.rs @@ -1,11 +1,12 @@ extern crate notify; extern crate resolv_conf; +use std::io::{self, Write}; use std::net::IpAddr; use std::ops::DerefMut; use std::path::Path; use std::sync::{mpsc, Arc, Mutex, MutexGuard}; -use std::{fs, io, thread}; +use std::{fs, thread}; use error_chain::ChainedError; @@ -106,7 +107,14 @@ impl DnsSettings { match fs::read(&backup_file) { Ok(backup) => { info!("Restoring DNS state from backup"); - fs::write(RESOLV_CONF_PATH, &backup).chain_err(|| ErrorKind::RestoreResolvConf)?; + let mut conf_file = + fs::File::create(RESOLV_CONF_PATH).chain_err(|| ErrorKind::RestoreResolvConf)?; + conf_file + .write_all(&backup) + .chain_err(|| ErrorKind::RestoreResolvConf)?; + conf_file + .sync_all() + .chain_err(|| ErrorKind::RestoreResolvConf)?; fs::remove_file(&backup_file).chain_err(|| ErrorKind::RemoveBackup)?; } Err(ref error) if error.kind() == io::ErrorKind::NotFound => { diff --git a/talpid-core/src/firewall/windows/system_state.rs b/talpid-core/src/firewall/windows/system_state.rs index 4695c13bc4..8c310667bb 100644 --- a/talpid-core/src/firewall/windows/system_state.rs +++ b/talpid-core/src/firewall/windows/system_state.rs @@ -24,7 +24,9 @@ impl SystemStateWriter { /// Writes a binary blob representing the system state to the backup location before any /// security policies are applied. pub fn write_backup(&self, data: &[u8]) -> io::Result<()> { - fs::write(&self.backup_path, &data) + let mut backup_file = File::create(&self.backup_path)?; + backup_file.write_all(data)?; + backup_file.sync_all() } pub fn read_backup(&self) -> io::Result<Option<Vec<u8>>> { |
