diff options
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/rpc_address_file.rs | 14 |
2 files changed, 14 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c3804f41f4..94bb2b60d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ Line wrap the file at 100 chars. Th - Fix log newline characters on Windows. - Mullvad CLI can now be used with daemon instance that doesn't have the `--disable-rpc-auth` flag set. +- If necessary, create parent directories for RPC connection info file. ## [2018.1] - 2018-03-01 diff --git a/mullvad-daemon/src/rpc_address_file.rs b/mullvad-daemon/src/rpc_address_file.rs index 2280c6377f..a59a7eb485 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()) @@ -20,13 +27,18 @@ error_chain! { } } -/// Writes down the RPC connection info to some API to a file. +/// Writes down the RPC connection info to the RPC file. pub fn write(rpc_address: &str, shared_secret: &str) -> Result<()> { // Avoids opening an existing file owned by another user and writing sensitive data to it. remove()?; 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()))?; |
