fix(config): check default_path if key_path fails
This commit is contained in:
parent
3e6f314c6b
commit
52491e08ee
1 changed files with 12 additions and 8 deletions
|
|
@ -280,14 +280,18 @@ impl ConfigGet for Config {
|
||||||
//TODO: check for transaction
|
//TODO: check for transaction
|
||||||
fn get<T: DeserializeOwned>(&self, key: &str) -> Result<T, Error> {
|
fn get<T: DeserializeOwned>(&self, key: &str) -> Result<T, Error> {
|
||||||
// If key path exists
|
// If key path exists
|
||||||
let key_path = self.key_path(key)?;
|
let key_path = self.key_path(key);
|
||||||
let data = if key_path.is_file() {
|
let data = match key_path {
|
||||||
// Load user override
|
Ok(key_path) if key_path.is_file() => {
|
||||||
fs::read_to_string(key_path).map_err(|err| Error::GetKey(key.to_string(), err))?
|
// Load user override
|
||||||
} else {
|
fs::read_to_string(key_path).map_err(|err| Error::GetKey(key.to_string(), err))?
|
||||||
// Load system default
|
}
|
||||||
let default_path = self.default_path(key)?;
|
_ => {
|
||||||
fs::read_to_string(default_path).map_err(|err| Error::GetKey(key.to_string(), err))?
|
// Load system default
|
||||||
|
let default_path = self.default_path(key)?;
|
||||||
|
fs::read_to_string(default_path)
|
||||||
|
.map_err(|err| Error::GetKey(key.to_string(), err))?
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let t = ron::from_str(&data)?;
|
let t = ron::from_str(&data)?;
|
||||||
Ok(t)
|
Ok(t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue