config/datastore.rs: return empty config if file does not exist

This commit is contained in:
Dietmar Maurer 2019-02-16 10:06:08 +01:00
parent 12400210a2
commit d11594db4c

View File

@ -40,8 +40,17 @@ pub fn config() -> Result<SectionConfigData, Error> {
let mut contents = String::new();
try_block!({
let mut file = std::fs::File::open(DATASTORE_CFG_FILENAME)?;
file.read_to_string(&mut contents)
match std::fs::File::open(DATASTORE_CFG_FILENAME) {
Ok(mut file) => file.read_to_string(&mut contents),
Err(err) => {
if err.kind() == std::io::ErrorKind::NotFound {
contents = String::from("");
Ok(0)
} else {
Err(err)
}
}
}
}).map_err(|e| format_err!("unable to read '{}' - {}", DATASTORE_CFG_FILENAME, e))?;
CONFIG.parse(DATASTORE_CFG_FILENAME, &contents)