diff options
| -rw-r--r-- | mullvad-daemon/src/rpc_address_file.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/mullvad-daemon/src/rpc_address_file.rs b/mullvad-daemon/src/rpc_address_file.rs index 2280c6377f..305522260c 100644 --- a/mullvad-daemon/src/rpc_address_file.rs +++ b/mullvad-daemon/src/rpc_address_file.rs @@ -9,6 +9,13 @@ error_chain! { UnknownFilePath { description("Failed to find path for RPC connection info file") } + CreateDirFailed(path: PathBuf) { + description("Failed to create directory for RPC connection info file") + display( + "Failed to create directory for RPC connection info file: {}", + path.to_string_lossy(), + ) + } WriteFailed(path: PathBuf) { description("Failed to write RPC connection info to file") display("Failed to write RPC connection info to {}", path.to_string_lossy()) @@ -27,6 +34,11 @@ pub fn write(rpc_address: &str, shared_secret: &str) -> Result<()> { let file_path = rpc_file_path().chain_err(|| ErrorKind::UnknownFilePath)?; + if let Some(parent_dir) = file_path.parent() { + fs::create_dir_all(parent_dir) + .chain_err(|| ErrorKind::CreateDirFailed(parent_dir.to_owned()))?; + } + open_file(&file_path) .and_then(|mut file| write!(file, "{}\n{}\n", rpc_address, shared_secret)) .chain_err(|| ErrorKind::WriteFailed(file_path.clone()))?; |
