diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-05-15 16:38:07 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-05-16 08:45:44 -0300 |
| commit | 40d0f1fb49ad7afb9732c520eee8f9b04307e628 (patch) | |
| tree | 81a6254a319abf6b68d468eaca8c7edc901813d6 | |
| parent | 539532d275ade3466c6040574c902e66c171d4e1 (diff) | |
| download | mullvadvpn-40d0f1fb49ad7afb9732c520eee8f9b04307e628.tar.xz mullvadvpn-40d0f1fb49ad7afb9732c520eee8f9b04307e628.zip | |
Create parent directories in RPC info file path
| -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()))?; |
