summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad_daemon/src/main.rs8
-rw-r--r--mullvad_daemon/src/rpc_info.rs11
2 files changed, 18 insertions, 1 deletions
diff --git a/mullvad_daemon/src/main.rs b/mullvad_daemon/src/main.rs
index eb360b3e8c..1177e05bd7 100644
--- a/mullvad_daemon/src/main.rs
+++ b/mullvad_daemon/src/main.rs
@@ -312,6 +312,14 @@ impl Daemon {
}
}
+impl Drop for Daemon {
+ fn drop(self: &mut Daemon) {
+ if let Err(e) = rpc_info::remove() {
+ log_error("Unable to clean up rpc address file", e);
+ }
+ }
+}
+
fn log_error<E>(msg: &str, error: E)
where E: error_chain::ChainedError
diff --git a/mullvad_daemon/src/rpc_info.rs b/mullvad_daemon/src/rpc_info.rs
index 302afbf719..145a57fb8a 100644
--- a/mullvad_daemon/src/rpc_info.rs
+++ b/mullvad_daemon/src/rpc_info.rs
@@ -1,4 +1,4 @@
-use std::fs::{File, OpenOptions};
+use std::fs::{self, File, OpenOptions};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
@@ -8,6 +8,10 @@ error_chain! {
description("Failed to write RCP address to file")
display("Failed to write RPC address to {}", path.to_string_lossy())
}
+ RemoveFailed(path: PathBuf) {
+ description("Failed to remove file")
+ display("Failed to remove {}", path.to_string_lossy())
+ }
}
}
@@ -29,6 +33,11 @@ pub fn write(rpc_address: &str) -> Result<()> {
Ok(())
}
+pub fn remove() -> Result<()> {
+ fs::remove_file(*RPC_ADDRESS_FILE_PATH)
+ .chain_err(|| ErrorKind::RemoveFailed(RPC_ADDRESS_FILE_PATH.to_owned()))
+}
+
fn open_file(path: &Path) -> io::Result<File> {
OpenOptions::new()
.write(true)