From c0c62bd1b5c5b9ece1d8289721dc8617987a7885 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Aug 2017 17:53:08 +0200 Subject: Change crates to use toml-query crate --- lib/core/libimagrt/Cargo.toml | 1 + lib/core/libimagrt/src/configuration.rs | 7 +++-- lib/core/libimagrt/src/lib.rs | 1 + lib/domain/libimagnotes/Cargo.toml | 1 + lib/domain/libimagnotes/src/lib.rs | 1 + lib/domain/libimagnotes/src/note.rs | 6 ++-- lib/entry/libimagentryannotation/Cargo.toml | 1 + .../libimagentryannotation/src/annotateable.rs | 20 ++++++-------- .../src/annotation_fetcher.rs | 8 +++--- lib/entry/libimagentryannotation/src/lib.rs | 1 + lib/entry/libimagentryfilter/Cargo.toml | 1 + .../src/builtin/header/field_eq.rs | 4 +-- .../src/builtin/header/field_exists.rs | 5 ++-- .../src/builtin/header/field_grep.rs | 8 +++--- .../src/builtin/header/field_gt.rs | 6 ++-- .../src/builtin/header/field_isempty.rs | 14 +++++----- .../src/builtin/header/field_istype.rs | 4 +-- .../src/builtin/header/field_lt.rs | 6 ++-- .../src/builtin/header/field_predicate.rs | 5 ++-- .../src/builtin/header/version/eq.rs | 6 ++-- .../src/builtin/header/version/gt.rs | 6 ++-- .../src/builtin/header/version/lt.rs | 6 ++-- lib/entry/libimagentryfilter/src/lib.rs | 1 + lib/entry/libimagentrylink/Cargo.toml | 1 + lib/entry/libimagentrylink/src/external.rs | 10 ++++--- lib/entry/libimagentrylink/src/internal.rs | 32 +++++++++++++++++----- lib/entry/libimagentrylink/src/lib.rs | 1 + lib/entry/libimagentryref/Cargo.toml | 1 + lib/entry/libimagentryref/src/flags.rs | 4 +-- lib/entry/libimagentryref/src/lib.rs | 1 + lib/entry/libimagentryref/src/reference.rs | 23 ++++++++-------- lib/entry/libimagentrytag/Cargo.toml | 1 + lib/entry/libimagentrytag/src/lib.rs | 1 + lib/entry/libimagentrytag/src/tagable.rs | 10 ++++--- 34 files changed, 121 insertions(+), 83 deletions(-) (limited to 'lib') diff --git a/lib/core/libimagrt/Cargo.toml b/lib/core/libimagrt/Cargo.toml index 4f0f0863..0599e233 100644 --- a/lib/core/libimagrt/Cargo.toml +++ b/lib/core/libimagrt/Cargo.toml @@ -23,6 +23,7 @@ itertools = "0.5" tempfile = "2.1" ansi_term = "0.9" is-match = "0.1" +toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index dcb3326b..bc3b52b4 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -133,7 +133,8 @@ impl Configuration { use self::error::ConfigErrorKind as CEK; use self::error::MapErrInto; use libimagerror::into::IntoError; - use libimagstore::toml_ext::TomlValueExt; + + use toml_query::read::TomlValueReadExt; v.into_iter() .map(|s| { debug!("Trying to process '{}'", s); s }) @@ -170,10 +171,10 @@ impl Configuration { /// Returns None if string cannot be converted. /// /// Arrays and Tables are not supported and will yield `None`. -fn into_value(value: Value, s: String) -> Option { +fn into_value(value: &Value, s: String) -> Option { use std::str::FromStr; - match value { + match *value { Value::String(_) => Some(Value::String(s)), Value::Integer(_) => FromStr::from_str(&s[..]).ok().map(Value::Integer), Value::Float(_) => FromStr::from_str(&s[..]).ok().map(Value::Float), diff --git a/lib/core/libimagrt/src/lib.rs b/lib/core/libimagrt/src/lib.rs index 55398013..a28b525f 100644 --- a/lib/core/libimagrt/src/lib.rs +++ b/lib/core/libimagrt/src/lib.rs @@ -42,6 +42,7 @@ extern crate ansi_term; extern crate clap; extern crate toml; +extern crate toml_query; #[macro_use] extern crate is_match; extern crate libimagstore; diff --git a/lib/domain/libimagnotes/Cargo.toml b/lib/domain/libimagnotes/Cargo.toml index d3616cde..3b19375a 100644 --- a/lib/domain/libimagnotes/Cargo.toml +++ b/lib/domain/libimagnotes/Cargo.toml @@ -17,6 +17,7 @@ homepage = "http://imag-pim.org" semver = "0.5" log = "0.3" toml = "^0.4" +toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/domain/libimagnotes/src/lib.rs b/lib/domain/libimagnotes/src/lib.rs index 10ef952b..3fa1f5d2 100644 --- a/lib/domain/libimagnotes/src/lib.rs +++ b/lib/domain/libimagnotes/src/lib.rs @@ -36,6 +36,7 @@ #[macro_use] extern crate log; extern crate semver; extern crate toml; +extern crate toml_query; extern crate libimagrt; #[macro_use] extern crate libimagstore; diff --git a/lib/domain/libimagnotes/src/note.rs b/lib/domain/libimagnotes/src/note.rs index cc50bab8..74991146 100644 --- a/lib/domain/libimagnotes/src/note.rs +++ b/lib/domain/libimagnotes/src/note.rs @@ -30,7 +30,9 @@ use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreIdIterator; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; -use libimagstore::toml_ext::TomlValueExt; + +use toml_query::read::TomlValueReadExt; +use toml_query::set::TomlValueSetExt; use module_path::ModuleEntryPath; use result::Result; @@ -92,7 +94,7 @@ impl<'a> Note<'a> { pub fn get_name(&self) -> Result { let header = self.entry.get_header(); match header.read("note.name") { - Ok(Some(Value::String(s))) => Ok(String::from(s)), + Ok(Some(&Value::String(ref s))) => Ok(s.clone()), Ok(_) => { let e = NE::new(NEK::HeaderTypeError, None); Err(NE::new(NEK::StoreReadError, Some(Box::new(e)))) diff --git a/lib/entry/libimagentryannotation/Cargo.toml b/lib/entry/libimagentryannotation/Cargo.toml index a0ceb99a..33666606 100644 --- a/lib/entry/libimagentryannotation/Cargo.toml +++ b/lib/entry/libimagentryannotation/Cargo.toml @@ -13,6 +13,7 @@ license = "LGPL-2.1" uuid = { version = "0.3.1", features = ["v4"] } lazy_static = "0.1.15" toml = "^0.4" +toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/entry/libimagentryannotation/src/annotateable.rs b/lib/entry/libimagentryannotation/src/annotateable.rs index 8827916a..4fb3589a 100644 --- a/lib/entry/libimagentryannotation/src/annotateable.rs +++ b/lib/entry/libimagentryannotation/src/annotateable.rs @@ -24,10 +24,12 @@ use toml::Value; use libimagstore::store::Entry; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; -use libimagstore::toml_ext::TomlValueExt; use libimagentrylink::internal::InternalLinker; use libimagerror::into::IntoError; +use toml_query::read::TomlValueReadExt; +use toml_query::insert::TomlValueInsertExt; + use result::Result; use error::AnnotationErrorKind as AEK; use error::MapErrInto; @@ -53,14 +55,8 @@ impl Annotateable for Entry { .and_then(|mut anno| { anno.get_header_mut() .insert("annotation.is_annotation", Value::Boolean(true)) - .map_err_into(AEK::StoreWriteError) - .and_then(|succeeded| { - if succeeded { - Ok(anno) - } else { - Err(AEK::HeaderWriteError.into_error()) - } - }) + .map_err_into(AEK::HeaderWriteError) + .map(|_| anno) }) .and_then(|mut anno| { anno.add_internal_link(self) @@ -74,9 +70,9 @@ impl Annotateable for Entry { .read("annotation.is_annotation") .map_err_into(AEK::StoreReadError) .and_then(|res| match res { - Some(Value::Boolean(b)) => Ok(b), - None => Ok(false), - _ => Err(AEK::HeaderTypeError.into_error()), + Some(&Value::Boolean(b)) => Ok(b), + None => Ok(false), + _ => Err(AEK::HeaderTypeError.into_error()), }) } diff --git a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs index 18c4a8be..58b27170 100644 --- a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs +++ b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs @@ -68,7 +68,8 @@ impl<'a> AnnotationFetcher<'a> for Store { pub mod iter { use toml::Value; - use libimagstore::toml_ext::TomlValueExt; + use toml_query::read::TomlValueReadExt; + use libimagerror::into::IntoError; use libimagnotes::note::Note; use libimagnotes::note::NoteIterator; @@ -95,10 +96,9 @@ pub mod iter { loop { match self.0.next() { Some(Ok(note)) => { - let hdr = note.get_header().read("annotation.is_annotation"); - match hdr { + match note.get_header().read("annotation.is_annotation") { Ok(None) => continue, // not an annotation - Ok(Some(Value::Boolean(true))) => return Some(Ok(note)), + Ok(Some(&Value::Boolean(true))) => return Some(Ok(note)), Ok(Some(_)) => return Some(Err(AEK::HeaderTypeError.into_error())), Err(e) => return Some(Err(e).map_err_into(AEK::HeaderReadError)), } diff --git a/lib/entry/libimagentryannotation/src/lib.rs b/lib/entry/libimagentryannotation/src/lib.rs index 0cb4e779..c84e342f 100644 --- a/lib/entry/libimagentryannotation/src/lib.rs +++ b/lib/entry/libimagentryannotation/src/lib.rs @@ -19,6 +19,7 @@ extern crate uuid; extern crate toml; +extern crate toml_query; #[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagstore; diff --git a/lib/entry/libimagentryfilter/Cargo.toml b/lib/entry/libimagentryfilter/Cargo.toml index decdc730..ea4df09d 100644 --- a/lib/entry/libimagentryfilter/Cargo.toml +++ b/lib/entry/libimagentryfilter/Cargo.toml @@ -21,6 +21,7 @@ log = "0.3" regex = "0.2" semver = "0.5.*" toml = "^0.4" +toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagentrytag = { version = "0.4.0", path = "../../../lib/entry/libimagentrytag" } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs index f10f3d0f..e2051958 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs @@ -32,8 +32,8 @@ struct EqPred { impl Predicate for EqPred { - fn evaluate(&self, v: Value) -> bool { - self.expected == v + fn evaluate(&self, v: &Value) -> bool { + self.expected == *v } } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs index 5fe672da..d793450a 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs @@ -18,11 +18,12 @@ // use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; -use builtin::header::field_path::FieldPath; +use toml_query::read::TomlValueReadExt; use filters::filter::Filter; +use builtin::header::field_path::FieldPath; + pub struct FieldExists { header_field_path: FieldPath, } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs index 799fee68..c6cdb624 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs @@ -33,10 +33,10 @@ struct EqGrep{ impl Predicate for EqGrep { - fn evaluate(&self, v: Value) -> bool { - match v { - Value::String(s) => self.regex.captures(&s[..]).is_some(), - _ => false, + fn evaluate(&self, v: &Value) -> bool { + match *v { + Value::String(ref s) => self.regex.captures(&s[..]).is_some(), + _ => false, } } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs index 2c1bcf89..6d50ddf7 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs @@ -32,17 +32,17 @@ struct EqGt { impl Predicate for EqGt { - fn evaluate(&self, v: Value) -> bool { + fn evaluate(&self, v: &Value) -> bool { match self.comp { Value::Integer(i) => { - match v { + match *v { Value::Integer(j) => i > j, Value::Float(f) => (i as f64) > f, _ => false, } }, Value::Float(f) => { - match v { + match *v { Value::Integer(i) => f > (i as f64), Value::Float(d) => f > d, _ => false, diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs index 7a9c6521..57003e32 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs @@ -18,7 +18,7 @@ // use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; +use toml_query::read::TomlValueReadExt; use builtin::header::field_path::FieldPath; use filters::filter::Filter; @@ -46,12 +46,12 @@ impl Filter for FieldIsEmpty { .read(&self.header_field_path[..]) .map(|v| { match v { - Some(Value::Array(a)) => a.is_empty(), - Some(Value::String(s)) => s.is_empty(), - Some(Value::Table(t)) => t.is_empty(), - Some(Value::Boolean(_)) | - Some(Value::Float(_)) | - Some(Value::Integer(_)) => false, + Some(&Value::Array(ref a)) => a.is_empty(), + Some(&Value::String(ref s)) => s.is_empty(), + Some(&Value::Table(ref t)) => t.is_empty(), + Some(&Value::Boolean(_)) | + Some(&Value::Float(_)) | + Some(&Value::Integer(_)) => false, _ => true, } }) diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs index 889c8321..471f772f 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs @@ -58,8 +58,8 @@ struct IsTypePred { impl Predicate for IsTypePred { - fn evaluate(&self, v: Value) -> bool { - self.ty.matches(&v) + fn evaluate(&self, v: &Value) -> bool { + self.ty.matches(v) } } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs index 0316bf82..7a3e8445 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs @@ -32,17 +32,17 @@ struct EqLt { impl Predicate for EqLt { - fn evaluate(&self, v: Value) -> bool { + fn evaluate(&self, v: &Value) -> bool { match self.comp { Value::Integer(i) => { - match v { + match *v { Value::Integer(j) => i < j, Value::Float(f) => (i as f64) < f, _ => false, } }, Value::Float(f) => { - match v { + match *v { Value::Integer(i) => f < (i as f64), Value::Float(d) => f < d, _ => false, diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs index 45aa332c..a167f762 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs @@ -18,7 +18,8 @@ // use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; + +use toml_query::read::TomlValueReadExt; use builtin::header::field_path::FieldPath; use filters::filter::Filter; @@ -26,7 +27,7 @@ use filters::filter::Filter; use toml::Value; pub trait Predicate { - fn evaluate(&self, Value) -> bool; + fn evaluate(&self, &Value) -> bool; } /// Check whether certain header field in a entry is equal to a value diff --git a/lib/entry/libimagentryfilter/src/builtin/header/version/eq.rs b/lib/entry/libimagentryfilter/src/builtin/header/version/eq.rs index 1ca38f8b..5ba9f306 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/version/eq.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/version/eq.rs @@ -21,8 +21,8 @@ use semver::Version; use toml::Value; use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; +use toml_query::read::TomlValueReadExt; use filters::filter::Filter; pub struct VersionEq { @@ -44,8 +44,8 @@ impl Filter for VersionEq { .read("imag.version") .map(|val| { val.map_or(false, |v| { - match v { - Value::String(s) => { + match *v { + Value::String(ref s) => { match Version::parse(&s[..]) { Ok(v) => v == self.version, _ => false diff --git a/lib/entry/libimagentryfilter/src/builtin/header/version/gt.rs b/lib/entry/libimagentryfilter/src/builtin/header/version/gt.rs index 8e3873fb..edd0580f 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/version/gt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/version/gt.rs @@ -21,8 +21,8 @@ use semver::Version; use toml::Value; use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; +use toml_query::read::TomlValueReadExt; use filters::filter::Filter; pub struct VersionGt { @@ -44,8 +44,8 @@ impl Filter for VersionGt { .read("imag.version") .map(|val| { val.map_or(false, |v| { - match v { - Value::String(s) => { + match *v { + Value::String(ref s) => { match Version::parse(&s[..]) { Ok(v) => v > self.version, _ => false diff --git a/lib/entry/libimagentryfilter/src/builtin/header/version/lt.rs b/lib/entry/libimagentryfilter/src/builtin/header/version/lt.rs index c475b436..629be9ae 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/version/lt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/version/lt.rs @@ -21,8 +21,8 @@ use semver::Version; use toml::Value; use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; +use toml_query::read::TomlValueReadExt; use filters::filter::Filter; pub struct VersionLt { @@ -44,8 +44,8 @@ impl Filter for VersionLt { .read("imag.version") .map(|val| { val.map_or(false, |v| { - match v { - Value::String(s) => { + match *v { + Value::String(ref s) => { match Version::parse(&s[..]) { Ok(v) => v < self.version, _ => false diff --git a/lib/entry/libimagentryfilter/src/lib.rs b/lib/entry/libimagentryfilter/src/lib.rs index ad99db60..9f4fc84e 100644 --- a/lib/entry/libimagentryfilter/src/lib.rs +++ b/lib/entry/libimagentryfilter/src/lib.rs @@ -37,6 +37,7 @@ extern crate itertools; extern crate regex; extern crate semver; extern crate toml; +extern crate toml_query; extern crate libimagstore; extern crate libimagentrytag; diff --git a/lib/entry/libimagentrylink/Cargo.toml b/lib/entry/libimagentrylink/Cargo.toml index 32e86873..a0118b18 100644 --- a/lib/entry/libimagentrylink/Cargo.toml +++ b/lib/entry/libimagentrylink/Cargo.toml @@ -22,6 +22,7 @@ url = "1.2" rust-crypto = "0.2" env_logger = "0.3" is-match = "0.1" +toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/entry/libimagentrylink/src/external.rs b/lib/entry/libimagentrylink/src/external.rs index daed7a12..8ebd060d 100644 --- a/lib/entry/libimagentrylink/src/external.rs +++ b/lib/entry/libimagentrylink/src/external.rs @@ -39,9 +39,11 @@ use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; -use libimagstore::toml_ext::TomlValueExt; use libimagutil::debug_result::*; +use toml_query::read::TomlValueReadExt; +use toml_query::set::TomlValueSetExt; + use error::LinkError as LE; use error::LinkErrorKind as LEK; use error::MapErrInto; @@ -73,7 +75,7 @@ impl<'a> Link<'a> { .read("imag.content.url") .ok() .and_then(|opt| match opt { - Some(Value::String(s)) => { + Some(&Value::String(ref s)) => { debug!("Found url, parsing: {:?}", s); Url::parse(&s[..]).ok() }, @@ -87,7 +89,7 @@ impl<'a> Link<'a> { .read("imag.content.url"); match opt { - Ok(Some(Value::String(s))) => { + Ok(Some(&Value::String(ref s))) => { Url::parse(&s[..]) .map(Some) .map_err(|e| LE::new(LEK::EntryHeaderReadError, Some(Box::new(e)))) @@ -351,7 +353,7 @@ impl ExternalLinker for Entry { let mut hdr = file.deref_mut().get_header_mut(); let mut table = match hdr.read("imag.content") { - Ok(Some(Value::Table(table))) => table, + Ok(Some(&Value::Table(ref table))) => table.clone(), Ok(Some(_)) => { warn!("There is a value at 'imag.content' which is not a table."); warn!("Going to override this value"); diff --git a/lib/entry/libimagentrylink/src/internal.rs b/lib/entry/libimagentrylink/src/internal.rs index 62003777..8e33d8d8 100644 --- a/lib/entry/libimagentrylink/src/internal.rs +++ b/lib/entry/libimagentrylink/src/internal.rs @@ -25,9 +25,11 @@ use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; use libimagstore::store::Entry; use libimagstore::store::Result as StoreResult; -use libimagstore::toml_ext::TomlValueExt; use libimagerror::into::IntoError; +use toml_query::read::TomlValueReadExt; +use toml_query::set::TomlValueSetExt; + use error::LinkErrorKind as LEK; use error::MapErrInto; use result::Result; @@ -388,7 +390,12 @@ pub mod iter { impl InternalLinker for Entry { fn get_internal_links(&self) -> Result { - process_rw_result(self.get_header().read("imag.links")) + let res = self + .get_header() + .read("imag.links") + .map_err_into(LEK::EntryHeaderReadError) + .map(|r| r.cloned()); + process_rw_result(res) } /// Set the links in a header and return the old links, if any. @@ -417,7 +424,11 @@ impl InternalLinker for Entry { }) }) })); - process_rw_result(self.get_header_mut().set("imag.links", Value::Array(new_links))) + let res = self + .get_header_mut() + .set("imag.links", Value::Array(new_links)) + .map_err_into(LEK::EntryHeaderReadError); + process_rw_result(res) } fn add_internal_link(&mut self, link: &mut Entry) -> Result<()> { @@ -485,7 +496,9 @@ fn rewrite_links>(header: &mut Value, links: I) -> Resu })); debug!("Setting new link array: {:?}", links); - let process = header.set("imag.links", Value::Array(links)); + let process = header + .set("imag.links", Value::Array(links)) + .map_err_into(LEK::EntryHeaderReadError); process_rw_result(process).map(|_| ()) } @@ -509,12 +522,17 @@ fn add_foreign_link(target: &mut Entry, from: StoreId) -> Result<()> { }) })); debug!("Setting links in {:?}: {:?}", target.get_location(), links); - process_rw_result(target.get_header_mut().set("imag.links", Value::Array(links))) - .map(|_| ()) + + let res = target + .get_header_mut() + .set("imag.links", Value::Array(links)) + .map_err_into(LEK::EntryHeaderReadError); + + process_rw_result(res).map(|_| ()) }) } -fn process_rw_result(links: StoreResult>) -> Result { +fn process_rw_result(links: Result>) -> Result { use std::path::PathBuf; let links = match links { diff --git a/lib/entry/libimagentrylink/src/lib.rs b/lib/entry/libimagentrylink/src/lib.rs index 2ed8b6ba..059a5d45 100644 --- a/lib/entry/libimagentrylink/src/lib.rs +++ b/lib/entry/libimagentrylink/src/lib.rs @@ -34,6 +34,7 @@ extern crate itertools; #[macro_use] extern crate log; extern crate toml; +extern crate toml_query; extern crate semver; extern crate url; extern crate crypto; diff --git a/lib/entry/libimagentryref/Cargo.toml b/lib/entry/libimagentryref/Cargo.toml index 7b7763e8..a60b8c9c 100644 --- a/lib/entry/libimagentryref/Cargo.toml +++ b/lib/entry/libimagentryref/Cargo.toml @@ -21,6 +21,7 @@ semver = "0.5" toml = "^0.4" version = "2.0.1" walkdir = "1.0.*" +toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/entry/libimagentryref/src/flags.rs b/lib/entry/libimagentryref/src/flags.rs index 6ddf2990..b3b6851c 100644 --- a/lib/entry/libimagentryref/src/flags.rs +++ b/lib/entry/libimagentryref/src/flags.rs @@ -37,13 +37,13 @@ impl RefFlags { /// It assumes that this is a Map with Key = and Value = boolean. pub fn read(v: &Value) -> Result { fn get_field(v: &Value, key: &str) -> Result { - use libimagstore::toml_ext::TomlValueExt; + use toml_query::read::TomlValueReadExt; use error::MapErrInto; v.read(key) .map_err_into(REK::HeaderTomlError) .and_then(|toml| match toml { - Some(Value::Boolean(b)) => Ok(b), + Some(&Value::Boolean(b)) => Ok(b), Some(_) => Err(REK::HeaderTypeError.into()), None => Err(REK::HeaderFieldMissingError.into()), }) diff --git a/lib/entry/libimagentryref/src/lib.rs b/lib/entry/libimagentryref/src/lib.rs index 86c187d0..6189a4e0 100644 --- a/lib/entry/libimagentryref/src/lib.rs +++ b/lib/entry/libimagentryref/src/lib.rs @@ -36,6 +36,7 @@ extern crate crypto; extern crate itertools; extern crate semver; extern crate toml; +extern crate toml_query; extern crate version; extern crate walkdir; diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs index e860452e..81e991ca 100644 --- a/lib/entry/libimagentryref/src/reference.rs +++ b/lib/entry/libimagentryref/src/reference.rs @@ -33,10 +33,12 @@ use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; use libimagstore::store::Store; -use libimagstore::toml_ext::TomlValueExt; use libimagerror::into::IntoError; use toml::Value; +use toml_query::read::TomlValueReadExt; +use toml_query::set::TomlValueSetExt; +use toml_query::insert::TomlValueInsertExt; use error::RefErrorKind as REK; use error::MapErrInto; @@ -89,7 +91,7 @@ impl<'a> Ref<'a> { fn read_reference(fle: &FileLockEntry<'a>) -> Result { match fle.get_header().read("ref.path") { - Ok(Some(Value::String(s))) => Ok(PathBuf::from(s)), + Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)), Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()), Ok(None) => Err(REK::HeaderFieldMissingError.into_error()), Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))), @@ -204,18 +206,17 @@ impl<'a> Ref<'a> { match tpl { &Some((ref s, ref v)) => { match fle.get_header_mut().insert(s, v.clone()) { - Ok(false) => { - let e = REK::HeaderFieldAlreadyExistsError.into_error(); - let e = Box::new(e); - let e = REK::HeaderFieldWriteError.into_error_with_cause(e); - return Err(e); + Ok(None) => { + debug!("Header insert worked"); + } + Ok(Some(val)) => { + debug!("Overwrote: {}, which was: {:?}", s, val); }, Err(e) => { let e = Box::new(e); let e = REK::HeaderFieldWriteError.into_error_with_cause(e); return Err(e); }, - _ => (), } } &None => { @@ -274,7 +275,7 @@ impl<'a> Ref<'a> { pub fn get_stored_hash_with_hasher(&self, h: &H) -> Result { match self.0.get_header().read(&format!("ref.content_hash.{}", h.hash_name())[..]) { // content hash stored... - Ok(Some(Value::String(s))) => Ok(s), + Ok(Some(&Value::String(ref s))) => Ok(s.clone()), // content hash header field has wrong type Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()), @@ -365,7 +366,7 @@ impl<'a> Ref<'a> { .map_err(|e| REK::HeaderFieldReadError.into_error_with_cause(e)) .and_then(|ro| { match ro { - Some(Value::Boolean(b)) => Ok(b), + Some(&Value::Boolean(b)) => Ok(b), Some(_) => Err(REK::HeaderTypeError.into_error()), None => Err(REK::HeaderFieldMissingError.into_error()), } @@ -414,7 +415,7 @@ impl<'a> Ref<'a> { /// Get the path of the file which is reffered to by this Ref pub fn fs_file(&self) -> Result { match self.0.get_header().read("ref.path") { - Ok(Some(Value::String(ref s))) => Ok(PathBuf::from(s)), + Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)), Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()), Ok(None) => Err(REK::HeaderFieldMissingError.into_error()), Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))), diff --git a/lib/entry/libimagentrytag/Cargo.toml b/lib/entry/libimagentrytag/Cargo.toml index a58b33d0..1732fb64 100644 --- a/lib/entry/libimagentrytag/Cargo.toml +++ b/lib/entry/libimagentrytag/Cargo.toml @@ -21,6 +21,7 @@ toml = "^0.4" itertools = "0.5" is-match = "0.1" filters = "0.1" +toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/entry/libimagentrytag/src/lib.rs b/lib/entry/libimagentrytag/src/lib.rs index bfc4d461..f50980d8 100644 --- a/lib/entry/libimagentrytag/src/lib.rs +++ b/lib/entry/libimagentrytag/src/lib.rs @@ -36,6 +36,7 @@ extern crate itertools; #[macro_use] extern crate log; extern crate regex; extern crate toml; +extern crate toml_query; #[macro_use] extern crate is_match; extern crate filters; diff --git a/lib/entry/libimagentrytag/src/tagable.rs b/lib/entry/libimagentrytag/src/tagable.rs index bd53a122..1a182e57 100644 --- a/lib/entry/libimagentrytag/src/tagable.rs +++ b/lib/entry/libimagentrytag/src/tagable.rs @@ -21,7 +21,9 @@ use itertools::Itertools; use libimagstore::store::Entry; use libimagerror::into::IntoError; -use libimagstore::toml_ext::TomlValueExt; + +use toml_query::read::TomlValueReadExt; +use toml_query::set::TomlValueSetExt; use error::TagErrorKind; use error::MapErrInto; @@ -50,7 +52,7 @@ impl Tagable for Value { let tags = try!(self.read("imag.tags").map_err_into(TagErrorKind::HeaderReadError)); match tags { - Some(Value::Array(tags)) => { + Some(&Value::Array(ref tags)) => { if !tags.iter().all(|t| is_match!(*t, Value::String(_))) { return Err(TagErrorKind::TagTypeError.into()); } @@ -120,7 +122,7 @@ impl Tagable for Value { fn has_tag(&self, t: TagSlice) -> Result { let tags = try!(self.read("imag.tags").map_err_into(TagErrorKind::HeaderReadError)); - if !tags.iter().all(|t| is_match!(*t, Value::String(_))) { + if !tags.iter().all(|t| is_match!(*t, &Value::String(_))) { return Err(TagErrorKind::TagTypeError.into()); } @@ -128,7 +130,7 @@ impl Tagable for Value { .iter() .any(|tag| { match *tag { - Value::String(ref s) => { s == t }, + &Value::String(ref s) => { s == t }, _ => unreachable!() } })) -- cgit v1.2.3