diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-10-16 11:18:48 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-10-16 11:18:48 +0300 |
commit | f7d5a9e11eed3f7f0769fbb154acb10bdc7fb58d (patch) | |
tree | e2e6e500848617920b53dd126c1392e4db49a2e2 /src/config.rs | |
parent | 21521cfe1b0870e8552d19b022ac0c3902eb356e (diff) | |
download | vmadm-f7d5a9e11eed3f7f0769fbb154acb10bdc7fb58d.tar.gz |
feat: allow ~user/ in path names, not just ~/
Add the home-dir crate as a dependency for tilde expansion.
Sponsored-by: author
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs index 6829151..9e91eb4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -53,6 +53,10 @@ pub enum ConfigurationError { /// YAML parsing error. #[error(transparent)] YamlError(#[from] serde_yaml::Error), + + /// Error expanding a ~user in a path name. + #[error(transparent)] + HomeDirError(#[from] home_dir::Error) } impl Configuration { @@ -63,7 +67,7 @@ impl Configuration { let config = fs::read(filename) .map_err(|err| ConfigurationError::ReadError(filename.to_path_buf(), err))?; let mut config: Configuration = serde_yaml::from_slice(&config)?; - config.expand_tildes(); + config.expand_tildes()?; config.fill_in_missing_networks(); debug!("config: {:#?}", config); Ok(config) @@ -78,11 +82,12 @@ impl Configuration { } } - fn expand_tildes(&mut self) { - expand_optional_pathbuf(&mut self.default_base_image); - expand_optional_pathbuf(&mut self.image_directory); - expand_optional_pathbuf(&mut self.image_directory); - expand_optional_pathbuf(&mut self.ca_key); - expand_optional_pathbufs(&mut self.authorized_keys) + fn expand_tildes(&mut self) -> Result<(), home_dir::Error> { + expand_optional_pathbuf(&mut self.default_base_image)?; + expand_optional_pathbuf(&mut self.image_directory)?; + expand_optional_pathbuf(&mut self.image_directory)?; + expand_optional_pathbuf(&mut self.ca_key)?; + expand_optional_pathbufs(&mut self.authorized_keys)?; + Ok(()) } } |