libimagstore: Replace read with typed read
This commit is contained in:
parent
febecd85e5
commit
3ef5fcfab6
2 changed files with 7 additions and 12 deletions
|
@ -26,15 +26,12 @@ use error::StoreErrorKind as SEK;
|
|||
/// Checks whether the store configuration has a key "implicit-create" which maps to a boolean
|
||||
/// value. If that key is present, the boolean is returned, otherwise false is returned.
|
||||
pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bool> {
|
||||
use toml_query::read::TomlValueReadExt;
|
||||
use toml_query::read::TomlValueReadTypeExt;
|
||||
|
||||
let key = "store.implicit-create";
|
||||
|
||||
if let Some(ref t) = *config {
|
||||
t.read(key)?
|
||||
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))?
|
||||
.as_bool()
|
||||
.ok_or(SE::from_kind(SEK::ConfigTypeError(key, "boolean")))
|
||||
t.read_bool(key)?.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ use glob::glob;
|
|||
use walkdir::WalkDir;
|
||||
use walkdir::Iter as WalkDirIter;
|
||||
use toml_query::read::TomlValueReadExt;
|
||||
use toml_query::read::TomlValueReadTypeExt;
|
||||
|
||||
use error::{StoreError as SE, StoreErrorKind as SEK};
|
||||
use error::ResultExt;
|
||||
|
@ -1102,13 +1103,10 @@ fn has_main_section(t: &Value) -> Result<bool> {
|
|||
}
|
||||
|
||||
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
|
||||
use toml_query::read::TomlValueReadExt;
|
||||
|
||||
t.read("imag.version")?
|
||||
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))?
|
||||
.as_str()
|
||||
.map(|s| ::semver::Version::parse(s).is_ok())
|
||||
.ok_or(SE::from_kind(SEK::ConfigTypeError("imag.version", "String")))
|
||||
t.read_string("imag.version")?
|
||||
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))
|
||||
.map(String::from)
|
||||
.map(|s| ::semver::Version::parse(&s).is_ok())
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue