summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-05-16 09:01:09 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-05-16 09:01:09 -0300
commit37e54738b50e9f84996e323e1d069bb3bcde421d (patch)
tree2953df6c9a94b8ea27b50f946ced797e4205ee94
parent539532d275ade3466c6040574c902e66c171d4e1 (diff)
parentf0fb96c5f911090ac7319167b26cc282919c45b2 (diff)
downloadmullvadvpn-37e54738b50e9f84996e323e1d069bb3bcde421d.tar.xz
mullvadvpn-37e54738b50e9f84996e323e1d069bb3bcde421d.zip
Merge branch 'create-rpc-file-dirs'
-rw-r--r--CHANGELOG.md1
-rw-r--r--mullvad-daemon/src/rpc_address_file.rs14
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()))?;