libimagentryref: Replace read with typed read
This commit is contained in:
parent
e9ae81a2ce
commit
a34cae03e5
3 changed files with 13 additions and 28 deletions
|
@ -38,12 +38,8 @@ impl RefFlags {
|
||||||
/// It assumes that this is a Map with Key = <name of the setting> and Value = boolean.
|
/// It assumes that this is a Map with Key = <name of the setting> and Value = boolean.
|
||||||
pub fn read(v: &Value) -> Result<RefFlags> {
|
pub fn read(v: &Value) -> Result<RefFlags> {
|
||||||
fn get_field(v: &Value, key: &str) -> Result<bool> {
|
fn get_field(v: &Value, key: &str) -> Result<bool> {
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
|
v.read_bool(key)?.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
|
||||||
v.read(key)?
|
|
||||||
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
|
|
||||||
.as_bool()
|
|
||||||
.ok_or(REK::HeaderTypeError.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RefFlags {
|
Ok(RefFlags {
|
||||||
|
|
|
@ -29,7 +29,7 @@ use libimagentryutil::isa::Is;
|
||||||
use libimagentryutil::isa::IsKindHeaderPathProvider;
|
use libimagentryutil::isa::IsKindHeaderPathProvider;
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
use toml_query::set::TomlValueSetExt;
|
use toml_query::set::TomlValueSetExt;
|
||||||
|
|
||||||
use error::RefErrorKind as REK;
|
use error::RefErrorKind as REK;
|
||||||
|
@ -152,11 +152,8 @@ impl Ref for Entry {
|
||||||
/// custom Hasher instance.
|
/// custom Hasher instance.
|
||||||
fn get_stored_hash_with_hasher<H: Hasher>(&self, h: &H) -> Result<String> {
|
fn get_stored_hash_with_hasher<H: Hasher>(&self, h: &H) -> Result<String> {
|
||||||
self.get_header()
|
self.get_header()
|
||||||
.read(&format!("ref.content_hash.{}", h.hash_name())[..])?
|
.read_string(&format!("ref.content_hash.{}", h.hash_name())[..])?
|
||||||
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
|
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
|
||||||
.as_str()
|
|
||||||
.map(String::from)
|
|
||||||
.ok_or(RE::from_kind(REK::HeaderTypeError))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the hash of the link target by reading the link target and hashing the contents
|
/// Get the hash of the link target by reading the link target and hashing the contents
|
||||||
|
@ -210,13 +207,9 @@ impl Ref for Entry {
|
||||||
fn fs_link_valid_permissions(&self) -> Result<bool> {
|
fn fs_link_valid_permissions(&self) -> Result<bool> {
|
||||||
self
|
self
|
||||||
.get_header()
|
.get_header()
|
||||||
.read("ref.permissions.ro")
|
.read_bool("ref.permissions.ro")
|
||||||
.chain_err(|| REK::HeaderFieldReadError)
|
.chain_err(|| REK::HeaderFieldReadError)?
|
||||||
.and_then(|ro| {
|
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
|
||||||
ro.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
|
|
||||||
.as_bool()
|
|
||||||
.ok_or(RE::from_kind(REK::HeaderTypeError))
|
|
||||||
})
|
|
||||||
.and_then(|ro| self.get_current_permissions().map(|perm| ro == perm.readonly()))
|
.and_then(|ro| self.get_current_permissions().map(|perm| ro == perm.readonly()))
|
||||||
.chain_err(|| REK::RefTargetCannotReadPermissions)
|
.chain_err(|| REK::RefTargetCannotReadPermissions)
|
||||||
}
|
}
|
||||||
|
@ -256,11 +249,9 @@ impl Ref for Entry {
|
||||||
/// Get the path of the file which is reffered to by this Ref
|
/// Get the path of the file which is reffered to by this Ref
|
||||||
fn fs_file(&self) -> Result<PathBuf> {
|
fn fs_file(&self) -> Result<PathBuf> {
|
||||||
self.get_header()
|
self.get_header()
|
||||||
.read("ref.path")?
|
.read_string("ref.path")?
|
||||||
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
|
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
|
||||||
.as_str()
|
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.ok_or(RE::from_kind(REK::HeaderTypeError))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Re-find a referenced file
|
/// Re-find a referenced file
|
||||||
|
|
|
@ -25,7 +25,7 @@ use error::Result;
|
||||||
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
|
|
||||||
/// Creates a Hash from a PathBuf by making the PathBuf absolute and then running a hash
|
/// Creates a Hash from a PathBuf by making the PathBuf absolute and then running a hash
|
||||||
/// algorithm on it
|
/// algorithm on it
|
||||||
|
@ -45,10 +45,8 @@ pub fn hash_path(pb: &PathBuf) -> Result<String> {
|
||||||
/// Read the reference from a file
|
/// Read the reference from a file
|
||||||
pub fn read_reference(refentry: &Entry) -> Result<PathBuf> {
|
pub fn read_reference(refentry: &Entry) -> Result<PathBuf> {
|
||||||
refentry.get_header()
|
refentry.get_header()
|
||||||
.read("ref.path")?
|
.read_string("ref.path")?
|
||||||
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
|
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
|
||||||
.as_str()
|
|
||||||
.ok_or(RE::from_kind(REK::HeaderTypeError))
|
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue