summaryrefslogtreecommitdiffstats
path: root/lib/entry/libimagentryref
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-01-12 16:32:18 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-01-13 01:14:03 +0100
commita34cae03e5732e025e449b01a1b89a442d26aeb4 (patch)
tree56a7ff512d9d4b5cd2b8523be3e9f731762e4f28 /lib/entry/libimagentryref
parente9ae81a2ce99a86035f68ec8c4ef335a3a4221aa (diff)
libimagentryref: Replace read with typed read
Diffstat (limited to 'lib/entry/libimagentryref')
-rw-r--r--lib/entry/libimagentryref/src/flags.rs8
-rw-r--r--lib/entry/libimagentryref/src/reference.rs25
-rw-r--r--lib/entry/libimagentryref/src/util.rs8
3 files changed, 13 insertions, 28 deletions
diff --git a/lib/entry/libimagentryref/src/flags.rs b/lib/entry/libimagentryref/src/flags.rs
index 21d822dd..fd80368c 100644
--- a/lib/entry/libimagentryref/src/flags.rs
+++ b/lib/entry/libimagentryref/src/flags.rs
@@ -38,12 +38,8 @@ impl RefFlags {
/// It assumes that this is a Map with Key = <name of the setting> and Value = boolean.
pub fn read(v: &Value) -> Result<RefFlags> {
fn get_field(v: &Value, key: &str) -> Result<bool> {
- use toml_query::read::TomlValueReadExt;
-
- v.read(key)?
- .ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
- .as_bool()
- .ok_or(REK::HeaderTypeError.into())
+ use toml_query::read::TomlValueReadTypeExt;
+ v.read_bool(key)?.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
}
Ok(RefFlags {
diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs
index 78c9d44f..1c1bdc84 100644
--- a/lib/entry/libimagentryref/src/reference.rs
+++ b/lib/entry/libimagentryref/src/reference.rs
@@ -29,7 +29,7 @@ use libimagentryutil::isa::Is;
use libimagentryutil::isa::IsKindHeaderPathProvider;
use toml::Value;
-use toml_query::read::TomlValueReadExt;
+use toml_query::read::TomlValueReadTypeExt;
use toml_query::set::TomlValueSetExt;
use error::RefErrorKind as REK;
@@ -152,11 +152,8 @@ impl Ref for Entry {
/// custom Hasher instance.
fn get_stored_hash_with_hasher<H: Hasher>(&self, h: &H) -> Result<String> {
self.get_header()
- .read(&format!("ref.content_hash.{}", h.hash_name())[..])?
- .ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
- .as_str()
- .map(String::from)
- .ok_or(RE::from_kind(REK::HeaderTypeError))
+ .read_string(&format!("ref.content_hash.{}", h.hash_name())[..])?
+ .ok_or(RE::from_kind(REK::HeaderFieldMissingError))
}
/// 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> {
self
.get_header()
- .read("ref.permissions.ro")
- .chain_err(|| REK::HeaderFieldReadError)
- .and_then(|ro| {
- ro.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
- .as_bool()
- .ok_or(RE::from_kind(REK::HeaderTypeError))
- })
+ .read_bool("ref.permissions.ro")
+ .chain_err(|| REK::HeaderFieldReadError)?
+ .ok_or(RE::from_kind(REK::HeaderFieldMissingError))
.and_then(|ro| self.get_current_permissions().map(|perm| ro == perm.readonly()))
.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
fn fs_file(&self) -> Result<PathBuf> {
self.get_header()
- .read("ref.path")?
- .ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
- .as_str()
+ .read_string("ref.path")?
+ .ok_or(RE::from_kind(REK::HeaderFieldMissingError))
.map(PathBuf::from)
- .ok_or(RE::from_kind(REK::HeaderTypeError))
}
/// Re-find a referenced file
diff --git a/lib/entry/libimagentryref/src/util.rs b/lib/entry/libimagentryref/src/util.rs
index 0055991d..ac4162fc 100644
--- a/lib/entry/libimagentryref/src/util.rs
+++ b/lib/entry/libimagentryref/src/util.rs
@@ -25,7 +25,7 @@ use error::Result;
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
/// algorithm on it
@@ -45,10 +45,8 @@ pub fn hash_path(pb: &PathBuf) -> Result<String> {
/// Read the reference from a file
pub fn read_reference(refentry: &Entry) -> Result<PathBuf> {
refentry.get_header()
- .read("ref.path")?
- .ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
- .as_str()
- .ok_or(RE::from_kind(REK::HeaderTypeError))
+ .read_string("ref.path")?
+ .ok_or(RE::from_kind(REK::HeaderFieldMissingError))
.map(PathBuf::from)
}