diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-04-10 14:34:24 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-04-17 07:33:50 -0300 |
| commit | 8b0a93ef4c1a3a5f7985c394c92aa87fb305f72a (patch) | |
| tree | ab2d56f09b57672b07454ffb5b17170ddfce2139 | |
| parent | 90db45c2baec09d6577bb2dbc6f16d5b046e6859 (diff) | |
| download | mullvadvpn-8b0a93ef4c1a3a5f7985c394c92aa87fb305f72a.tar.xz mullvadvpn-8b0a93ef4c1a3a5f7985c394c92aa87fb305f72a.zip | |
Separate functions that directly access the file
| -rw-r--r-- | talpid-core/src/firewall/linux/dns.rs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/talpid-core/src/firewall/linux/dns.rs b/talpid-core/src/firewall/linux/dns.rs index d2d1627dd0..da09a0fc47 100644 --- a/talpid-core/src/firewall/linux/dns.rs +++ b/talpid-core/src/firewall/linux/dns.rs @@ -37,7 +37,7 @@ impl DnsSettings { pub fn set_dns(&mut self, servers: Vec<IpAddr>) -> Result<()> { if self.backup.is_none() { - self.backup = Some(Self::read_resolv_conf().chain_err(|| ErrorKind::ReadResolvConf)?); + self.backup = Some(read_resolv_conf().chain_err(|| ErrorKind::ReadResolvConf)?); } self.desired_dns = Some(servers); @@ -50,7 +50,7 @@ impl DnsSettings { self.desired_dns = None; if let Some(backup) = self.backup.take() { - Self::write_resolv_conf(&backup).chain_err(|| ErrorKind::WriteResolvConf)?; + write_resolv_conf(&backup).chain_err(|| ErrorKind::WriteResolvConf)?; } Ok(()) @@ -73,21 +73,21 @@ impl DnsSettings { config.nameservers.clear(); } - Self::write_resolv_conf(&config.to_string()).chain_err(|| ErrorKind::WriteResolvConf) + write_resolv_conf(&config.to_string()).chain_err(|| ErrorKind::WriteResolvConf) } +} - fn read_resolv_conf() -> io::Result<String> { - let mut file = File::open("/etc/resolv.conf")?; - let mut contents = String::new(); +fn read_resolv_conf() -> io::Result<String> { + let mut file = File::open("/etc/resolv.conf")?; + let mut contents = String::new(); - file.read_to_string(&mut contents)?; + file.read_to_string(&mut contents)?; - Ok(contents) - } + Ok(contents) +} - fn write_resolv_conf(contents: &str) -> io::Result<()> { - let mut file = File::create("/etc/resolv.conf")?; +fn write_resolv_conf(contents: &str) -> io::Result<()> { + let mut file = File::create("/etc/resolv.conf")?; - file.write_all(contents.as_bytes()) - } + file.write_all(contents.as_bytes()) } |
