diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-03-05 13:35:34 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-03-06 14:06:22 -0300 |
| commit | c4330e821e496f3e1ffb4282a1c99795d9329e50 (patch) | |
| tree | 5a185d520e6929104abc8eaf005c95a808d76e37 | |
| parent | 805c34bd97323457425eab2adc335ca5290e16a9 (diff) | |
| download | mullvadvpn-c4330e821e496f3e1ffb4282a1c99795d9329e50.tar.xz mullvadvpn-c4330e821e496f3e1ffb4282a1c99795d9329e50.zip | |
Simplify log file backup creation
Perform a single operation to rename old log file into the backup log
file and to overwrite any existing backup.
| -rw-r--r-- | mullvad-daemon/src/main.rs | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index 37f36b7a6c..f4a033e5f0 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -656,34 +656,22 @@ impl Daemon { fn prepare_tunnel_log_file(&self) -> Result<()> { if let Some(ref file) = self.tunnel_log { - if file.exists() { - Self::backup_existing_tunnel_log_file(file); - } + let mut backup = file.clone(); + backup.set_extension("old.log"); + + fs::rename(file, backup).unwrap_or_else(|error| { + warn!( + "Failed to create backup of previous tunnel log file ({})", + error + ); + }); - let _ = fs::remove_file(file); fs::File::create(file).chain_err(|| "Unable to create the tunnel log file")?; } Ok(()) } - fn backup_existing_tunnel_log_file(log_file: &PathBuf) { - let mut backup = log_file.clone(); - backup.set_extension("old.log"); - - // Try to remove file first, in case rename fails to overwrite it - fs::remove_file(&backup).unwrap_or_else(|error| { - warn!("Failed to remove old backup of tunnel log file ({})", error); - }); - - fs::rename(log_file, backup).unwrap_or_else(|error| { - warn!( - "Failed to create backup of previous tunnel log file ({})", - error - ); - }); - } - fn spawn_tunnel_monitor( &self, tunnel_endpoint: TunnelEndpoint, |
