From d0f8002682b835f463e6e8e0125df14fa8ab83bf Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Aug 2017 18:06:20 +0200 Subject: [PATCH 01/17] Ensure deny() for warnings is in all crates --- lib/core/libimagerror/src/lib.rs | 2 ++ lib/core/libimagstore/src/lib.rs | 2 ++ lib/domain/libimagbookmark/src/lib.rs | 2 ++ lib/domain/libimagcounter/src/lib.rs | 2 ++ lib/domain/libimagmail/src/lib.rs | 16 ++++++++++++++++ lib/domain/libimagtimetrack/src/lib.rs | 16 ++++++++++++++++ lib/domain/libimagtodo/src/lib.rs | 2 ++ lib/entry/libimagentryannotation/src/lib.rs | 16 ++++++++++++++++ lib/entry/libimagentrycategory/src/lib.rs | 16 ++++++++++++++++ lib/entry/libimagentrydatetime/src/lib.rs | 16 ++++++++++++++++ lib/entry/libimagentryedit/src/lib.rs | 16 ++++++++++++++++ lib/entry/libimagentryfilter/src/lib.rs | 1 + lib/entry/libimagentrylink/src/lib.rs | 2 ++ lib/entry/libimagentrymarkdown/src/lib.rs | 2 ++ lib/entry/libimagentryref/src/lib.rs | 2 ++ lib/entry/libimagentrytag/src/lib.rs | 2 ++ lib/etc/libimaginteraction/src/lib.rs | 2 ++ lib/etc/libimagtimeui/src/lib.rs | 2 ++ lib/etc/libimagutil/src/lib.rs | 1 + 19 files changed, 120 insertions(+) diff --git a/lib/core/libimagerror/src/lib.rs b/lib/core/libimagerror/src/lib.rs index bc4f865d..0ed1e7f3 100644 --- a/lib/core/libimagerror/src/lib.rs +++ b/lib/core/libimagerror/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/core/libimagstore/src/lib.rs b/lib/core/libimagstore/src/lib.rs index ae205b83..afb40e80 100644 --- a/lib/core/libimagstore/src/lib.rs +++ b/lib/core/libimagstore/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/domain/libimagbookmark/src/lib.rs b/lib/domain/libimagbookmark/src/lib.rs index e576ff1d..e5a34357 100644 --- a/lib/domain/libimagbookmark/src/lib.rs +++ b/lib/domain/libimagbookmark/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/domain/libimagcounter/src/lib.rs b/lib/domain/libimagcounter/src/lib.rs index 09ba1786..13bf7367 100644 --- a/lib/domain/libimagcounter/src/lib.rs +++ b/lib/domain/libimagcounter/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/domain/libimagmail/src/lib.rs b/lib/domain/libimagmail/src/lib.rs index 23c9e60f..ae3fa850 100644 --- a/lib/domain/libimagmail/src/lib.rs +++ b/lib/domain/libimagmail/src/lib.rs @@ -17,6 +17,22 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +#![deny( + dead_code, + non_camel_case_types, + non_snake_case, + path_statements, + trivial_numeric_casts, + unstable_features, + unused_allocation, + unused_import_braces, + unused_imports, + unused_must_use, + unused_mut, + unused_qualifications, + while_true, +)] + #[macro_use] extern crate log; extern crate email; extern crate semver; diff --git a/lib/domain/libimagtimetrack/src/lib.rs b/lib/domain/libimagtimetrack/src/lib.rs index e3f9d2aa..0e92d2e8 100644 --- a/lib/domain/libimagtimetrack/src/lib.rs +++ b/lib/domain/libimagtimetrack/src/lib.rs @@ -17,6 +17,22 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +#![deny( + dead_code, + non_camel_case_types, + non_snake_case, + path_statements, + trivial_numeric_casts, + unstable_features, + unused_allocation, + unused_import_braces, + unused_imports, + unused_must_use, + unused_mut, + unused_qualifications, + while_true, +)] + extern crate filters; extern crate chrono; extern crate toml; diff --git a/lib/domain/libimagtodo/src/lib.rs b/lib/domain/libimagtodo/src/lib.rs index 16fcc11b..c1289f8d 100644 --- a/lib/domain/libimagtodo/src/lib.rs +++ b/lib/domain/libimagtodo/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/entry/libimagentryannotation/src/lib.rs b/lib/entry/libimagentryannotation/src/lib.rs index 0cb4e779..a4f335b6 100644 --- a/lib/entry/libimagentryannotation/src/lib.rs +++ b/lib/entry/libimagentryannotation/src/lib.rs @@ -17,6 +17,22 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +#![deny( + dead_code, + non_camel_case_types, + non_snake_case, + path_statements, + trivial_numeric_casts, + unstable_features, + unused_allocation, + unused_import_braces, + unused_imports, + unused_must_use, + unused_mut, + unused_qualifications, + while_true, +)] + extern crate uuid; extern crate toml; diff --git a/lib/entry/libimagentrycategory/src/lib.rs b/lib/entry/libimagentrycategory/src/lib.rs index 8ffaafc7..c2b4daae 100644 --- a/lib/entry/libimagentrycategory/src/lib.rs +++ b/lib/entry/libimagentrycategory/src/lib.rs @@ -17,6 +17,22 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +#![deny( + dead_code, + non_camel_case_types, + non_snake_case, + path_statements, + trivial_numeric_casts, + unstable_features, + unused_allocation, + unused_import_braces, + unused_imports, + unused_must_use, + unused_mut, + unused_qualifications, + while_true, +)] + extern crate toml_query; extern crate toml; #[macro_use] diff --git a/lib/entry/libimagentrydatetime/src/lib.rs b/lib/entry/libimagentrydatetime/src/lib.rs index fb0d73fa..06773d0f 100644 --- a/lib/entry/libimagentrydatetime/src/lib.rs +++ b/lib/entry/libimagentrydatetime/src/lib.rs @@ -17,6 +17,22 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +#![deny( + dead_code, + non_camel_case_types, + non_snake_case, + path_statements, + trivial_numeric_casts, + unstable_features, + unused_allocation, + unused_import_braces, + unused_imports, + unused_must_use, + unused_mut, + unused_qualifications, + while_true, +)] + #[macro_use] extern crate lazy_static; extern crate chrono; extern crate toml_query; diff --git a/lib/entry/libimagentryedit/src/lib.rs b/lib/entry/libimagentryedit/src/lib.rs index 00013d5e..9d9187cd 100644 --- a/lib/entry/libimagentryedit/src/lib.rs +++ b/lib/entry/libimagentryedit/src/lib.rs @@ -17,6 +17,22 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +#![deny( + dead_code, + non_camel_case_types, + non_snake_case, + path_statements, + trivial_numeric_casts, + unstable_features, + unused_allocation, + unused_import_braces, + unused_imports, + unused_must_use, + unused_mut, + unused_qualifications, + while_true, +)] + #[macro_use] extern crate libimagerror; extern crate libimagstore; extern crate libimagrt; diff --git a/lib/entry/libimagentryfilter/src/lib.rs b/lib/entry/libimagentryfilter/src/lib.rs index ad99db60..8b25c379 100644 --- a/lib/entry/libimagentryfilter/src/lib.rs +++ b/lib/entry/libimagentryfilter/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, diff --git a/lib/entry/libimagentrylink/src/lib.rs b/lib/entry/libimagentrylink/src/lib.rs index 2ed8b6ba..71562d9b 100644 --- a/lib/entry/libimagentrylink/src/lib.rs +++ b/lib/entry/libimagentrylink/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/entry/libimagentrymarkdown/src/lib.rs b/lib/entry/libimagentrymarkdown/src/lib.rs index 2efc6094..2d0ad848 100644 --- a/lib/entry/libimagentrymarkdown/src/lib.rs +++ b/lib/entry/libimagentrymarkdown/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/entry/libimagentryref/src/lib.rs b/lib/entry/libimagentryref/src/lib.rs index 86c187d0..b3291135 100644 --- a/lib/entry/libimagentryref/src/lib.rs +++ b/lib/entry/libimagentryref/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/entry/libimagentrytag/src/lib.rs b/lib/entry/libimagentrytag/src/lib.rs index bfc4d461..8c88f9b6 100644 --- a/lib/entry/libimagentrytag/src/lib.rs +++ b/lib/entry/libimagentrytag/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/etc/libimaginteraction/src/lib.rs b/lib/etc/libimaginteraction/src/lib.rs index 67c61cf4..b0663f8b 100644 --- a/lib/etc/libimaginteraction/src/lib.rs +++ b/lib/etc/libimaginteraction/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/etc/libimagtimeui/src/lib.rs b/lib/etc/libimagtimeui/src/lib.rs index b06bba78..b7652b57 100644 --- a/lib/etc/libimagtimeui/src/lib.rs +++ b/lib/etc/libimagtimeui/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, @@ -26,6 +27,7 @@ unused_allocation, unused_import_braces, unused_imports, + unused_must_use, unused_mut, unused_qualifications, while_true, diff --git a/lib/etc/libimagutil/src/lib.rs b/lib/etc/libimagutil/src/lib.rs index b5d30f51..81dce538 100644 --- a/lib/etc/libimagutil/src/lib.rs +++ b/lib/etc/libimagutil/src/lib.rs @@ -18,6 +18,7 @@ // #![deny( + dead_code, non_camel_case_types, non_snake_case, path_statements, From 7a7ea5c2113ab090a31484e7776fb254f7bcaa2f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Aug 2017 19:39:37 +0200 Subject: [PATCH 02/17] Add debug messages --- lib/domain/libimagmail/src/mail.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/domain/libimagmail/src/mail.rs b/lib/domain/libimagmail/src/mail.rs index 11b57398..ede27704 100644 --- a/lib/domain/libimagmail/src/mail.rs +++ b/lib/domain/libimagmail/src/mail.rs @@ -53,6 +53,7 @@ impl<'a> Mail<'a> { /// Imports a mail from the Path passed pub fn import_from_path>(store: &Store, p: P) -> Result { + debug!("Importing Mail from path"); let h = MailHasher::new(); let f = RefFlags::default().with_content_hashing(true).with_permission_tracking(false); let p = PathBuf::from(p.as_ref()); @@ -60,6 +61,7 @@ impl<'a> Mail<'a> { Ref::create_with_hasher(store, p, f, h) .map_err_into(MEK::RefCreationError) .and_then(|reference| { + debug!("Build reference file: {:?}", reference); reference.fs_file() .map_err_into(MEK::RefHandlingError) .and_then(|path| File::open(path).map_err_into(MEK::IOError)) @@ -76,6 +78,7 @@ impl<'a> Mail<'a> { /// Opens a mail by the passed hash pub fn open>(store: &Store, hash: S) -> Result> { + debug!("Opening Mail by Hash"); Ref::get_by_hash(store, String::from(hash.as_ref())) .map_err_into(MEK::FetchByHashError) .map_err_into(MEK::FetchError) @@ -88,6 +91,7 @@ impl<'a> Mail<'a> { /// Implement me as TryFrom as soon as it is stable pub fn from_ref(r: Ref<'a>) -> Result { + debug!("Building Mail object from Ref: {:?}", r); r.fs_file() .map_err_into(MEK::RefHandlingError) .and_then(|path| File::open(path).map_err_into(MEK::IOError)) @@ -102,6 +106,7 @@ impl<'a> Mail<'a> { } pub fn get_field(&self, field: &str) -> Result> { + debug!("Getting field in mail: {:?}", field); self.1 .parsed() .map_err_into(MEK::MailParsingError) From 286de656dffa30ba7ceacf57fc9ef2ebe3f22798 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Aug 2017 19:44:29 +0200 Subject: [PATCH 03/17] Handle UTF-8 Errors by returning --- lib/domain/libimagtodo/src/error.rs | 3 ++- lib/domain/libimagtodo/src/task.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/domain/libimagtodo/src/error.rs b/lib/domain/libimagtodo/src/error.rs index c19a6e52..621d3249 100644 --- a/lib/domain/libimagtodo/src/error.rs +++ b/lib/domain/libimagtodo/src/error.rs @@ -22,7 +22,8 @@ generate_error_module!( ConversionError => "Conversion Error", StoreError => "Store Error", StoreIdError => "Store Id handling error", - ImportError => "Error importing" + ImportError => "Error importing", + UTF8Error => "Encountered non-UTF8 characters while reading input" ); ); diff --git a/lib/domain/libimagtodo/src/task.rs b/lib/domain/libimagtodo/src/task.rs index 5e31d952..303ef14b 100644 --- a/lib/domain/libimagtodo/src/task.rs +++ b/lib/domain/libimagtodo/src/task.rs @@ -48,7 +48,7 @@ impl<'a> Task<'a> { pub fn import(store: &'a Store, mut r: R) -> Result<(Task<'a>, String, Uuid)> { let mut line = String::new(); - r.read_line(&mut line); + try!(r.read_line(&mut line).map_err_into(TEK::UTF8Error)); import_task(&line.as_str()) .map_err_into(TEK::ImportError) .and_then(|t| { @@ -70,7 +70,7 @@ impl<'a> Task<'a> { where R: BufRead { let mut line = String::new(); - r.read_line(&mut line); + try!(r.read_line(&mut line).map_err_into(TEK::UTF8Error)); Task::get_from_string(store, line) } @@ -104,7 +104,7 @@ impl<'a> Task<'a> { /// implicitely create the task if it does not exist. pub fn retrieve_from_import(store: &'a Store, mut r: R) -> Result> { let mut line = String::new(); - r.read_line(&mut line); + try!(r.read_line(&mut line).map_err_into(TEK::UTF8Error)); Task::retrieve_from_string(store, line) } From 75e42d2f0bd894f738b60957ae8902bd6f34f5d1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Aug 2017 19:41:55 +0200 Subject: [PATCH 04/17] Fix errors (former warnings) in several crates This fixes errors (former warnings) in several locations. --- lib/domain/libimagtimetrack/src/iter/filter.rs | 3 --- lib/domain/libimagtimetrack/src/iter/mod.rs | 5 +---- lib/entry/libimagentryannotation/src/lib.rs | 2 +- lib/entry/libimagentrydatetime/Cargo.toml | 3 --- lib/entry/libimagentrydatetime/src/lib.rs | 3 --- 5 files changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/domain/libimagtimetrack/src/iter/filter.rs b/lib/domain/libimagtimetrack/src/iter/filter.rs index 0a3ae538..57e9bc61 100644 --- a/lib/domain/libimagtimetrack/src/iter/filter.rs +++ b/lib/domain/libimagtimetrack/src/iter/filter.rs @@ -17,10 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use result::Result; - use chrono::NaiveDateTime; -use filters::filter::Filter; use libimagstore::store::FileLockEntry; diff --git a/lib/domain/libimagtimetrack/src/iter/mod.rs b/lib/domain/libimagtimetrack/src/iter/mod.rs index 467199d8..294f04c3 100644 --- a/lib/domain/libimagtimetrack/src/iter/mod.rs +++ b/lib/domain/libimagtimetrack/src/iter/mod.rs @@ -30,10 +30,7 @@ mod test { use libimagstore::store::Store; - use super::create::*; - use super::get::*; use super::setendtime::*; - use super::storeid::*; use super::tag::*; fn get_store() -> Store { @@ -53,7 +50,7 @@ mod test { let iter = tags.into_iter().map(String::from); - let iter : SetEndTimeIter = TagIter::new(Box::new(iter)) + let _ : SetEndTimeIter = TagIter::new(Box::new(iter)) .create_storeids(now) .create_entries(&store) .set_end_time(then); diff --git a/lib/entry/libimagentryannotation/src/lib.rs b/lib/entry/libimagentryannotation/src/lib.rs index a4f335b6..39129112 100644 --- a/lib/entry/libimagentryannotation/src/lib.rs +++ b/lib/entry/libimagentryannotation/src/lib.rs @@ -37,7 +37,7 @@ extern crate uuid; extern crate toml; #[macro_use] extern crate libimagerror; -#[macro_use] extern crate libimagstore; +extern crate libimagstore; extern crate libimagentrylink; extern crate libimagnotes; extern crate libimagutil; diff --git a/lib/entry/libimagentrydatetime/Cargo.toml b/lib/entry/libimagentrydatetime/Cargo.toml index 93e43b8c..a024c6d4 100644 --- a/lib/entry/libimagentrydatetime/Cargo.toml +++ b/lib/entry/libimagentrydatetime/Cargo.toml @@ -23,6 +23,3 @@ libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } -[dev-dependencies] -is-match = "0.1" - diff --git a/lib/entry/libimagentrydatetime/src/lib.rs b/lib/entry/libimagentrydatetime/src/lib.rs index 06773d0f..695ce974 100644 --- a/lib/entry/libimagentrydatetime/src/lib.rs +++ b/lib/entry/libimagentrydatetime/src/lib.rs @@ -42,9 +42,6 @@ extern crate toml; extern crate libimagstore; extern crate libimagutil; -#[cfg(test)] -#[macro_use] extern crate is_match; - pub mod datepath; pub mod datetime; pub mod error; From 43ca0b43b1ce1161902908d6ea53ed8ef14df0e6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Aug 2017 17:48:11 +0200 Subject: [PATCH 05/17] Move "Header" trait for toml::Value to store module --- lib/core/libimagstore/src/store.rs | 97 ++++++++++++++++++++++++++- lib/core/libimagstore/src/toml_ext.rs | 91 ------------------------- lib/core/libimagstore/src/util.rs | 2 +- 3 files changed, 97 insertions(+), 93 deletions(-) diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index a0ee33e5..aba0583d 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -18,6 +18,7 @@ // use std::collections::HashMap; +use std::collections::BTreeMap; use std::ops::Drop; use std::path::PathBuf; use std::result::Result as RResult; @@ -32,11 +33,12 @@ use std::fmt::Debug; use std::fmt::Error as FMTError; use toml::Value; +use toml::value::Table; use glob::glob; use walkdir::WalkDir; use walkdir::Iter as WalkDirIter; -use error::{StoreError as SE, StoreErrorKind as SEK}; +use error::{StoreError as SE, StoreErrorKind as SEK, ParserError, ParserErrorKind}; use error::MapErrInto; use storeid::{IntoStoreId, StoreId, StoreIdIterator}; use file_abstraction::FileAbstractionInstance; @@ -1115,6 +1117,96 @@ mod glob_store_iter { } +/// Extension trait for top-level toml::Value::Table, will only yield correct results on the +/// top-level Value::Table, but not on intermediate tables. +pub trait Header { + fn verify(&self) -> Result<()>; + fn parse(s: &str) -> RResult; + fn default_header() -> Value; +} + +impl Header for Value { + + fn verify(&self) -> Result<()> { + match *self { + Value::Table(ref t) => verify_header(&t), + _ => Err(SE::new(SEK::HeaderTypeFailure, None)), + } + } + + fn parse(s: &str) -> RResult { + use toml::de::from_str; + + from_str(s) + .map_err(|_| ParserErrorKind::TOMLParserErrors.into()) + .and_then(verify_header_consistency) + .map(Value::Table) + } + + fn default_header() -> Value { + let mut m = BTreeMap::new(); + + m.insert(String::from("imag"), { + let mut imag_map = BTreeMap::::new(); + + imag_map.insert(String::from("version"), Value::String(String::from(version!()))); + imag_map.insert(String::from("links"), Value::Array(vec![])); + + Value::Table(imag_map) + }); + + Value::Table(m) + } + +} + +fn verify_header_consistency(t: Table) -> RResult { + verify_header(&t) + .map_err(Box::new) + .map_err(|e| ParserErrorKind::HeaderInconsistency.into_error_with_cause(e)) + .map(|_| t) +} + +fn verify_header(t: &Table) -> Result<()> { + if !has_main_section(t) { + Err(SE::from(ParserErrorKind::MissingMainSection.into_error())) + } else if !has_imag_version_in_main_section(t) { + Err(SE::from(ParserErrorKind::MissingVersionInfo.into_error())) + } else if !has_only_tables(t) { + debug!("Could not verify that it only has tables in its base table"); + Err(SE::from(ParserErrorKind::NonTableInBaseTable.into_error())) + } else { + Ok(()) + } +} + +fn has_only_tables(t: &Table) -> bool { + debug!("Verifying that table has only tables"); + t.iter().all(|(_, x)| is_match!(*x, Value::Table(_))) +} + +fn has_main_section(t: &Table) -> bool { + t.contains_key("imag") && is_match!(t.get("imag"), Some(&Value::Table(_))) +} + +fn has_imag_version_in_main_section(t: &Table) -> bool { + use semver::Version; + + match *t.get("imag").unwrap() { + Value::Table(ref sec) => { + sec.get("version") + .and_then(|v| { + match *v { + Value::String(ref s) => Some(Version::parse(&s[..]).is_ok()), + _ => Some(false), + } + }) + .unwrap_or(false) + } + _ => false, + } +} + #[cfg(test)] mod test { @@ -1122,6 +1214,9 @@ mod test { use std::collections::BTreeMap; use storeid::StoreId; + use store::has_main_section; + use store::has_imag_version_in_main_section; + use store::verify_header_consistency; use toml::Value; diff --git a/lib/core/libimagstore/src/toml_ext.rs b/lib/core/libimagstore/src/toml_ext.rs index 9c0ae540..1e51ffd8 100644 --- a/lib/core/libimagstore/src/toml_ext.rs +++ b/lib/core/libimagstore/src/toml_ext.rs @@ -362,97 +362,6 @@ impl Extract for Value { pub type EntryResult = RResult; -/// Extension trait for top-level toml::Value::Table, will only yield correct results on the -/// top-level Value::Table, but not on intermediate tables. -pub trait Header { - fn verify(&self) -> Result<()>; - fn parse(s: &str) -> EntryResult; - fn default_header() -> Value; -} - -impl Header for Value { - - fn verify(&self) -> Result<()> { - match *self { - Value::Table(ref t) => verify_header(&t), - _ => Err(SE::new(SEK::HeaderTypeFailure, None)), - } - } - - fn parse(s: &str) -> EntryResult { - use toml::de::from_str; - - from_str(s) - .map_err(|_| ParserErrorKind::TOMLParserErrors.into()) - .and_then(verify_header_consistency) - .map(Value::Table) - } - - fn default_header() -> Value { - let mut m = BTreeMap::new(); - - m.insert(String::from("imag"), { - let mut imag_map = BTreeMap::::new(); - - imag_map.insert(String::from("version"), Value::String(String::from(version!()))); - imag_map.insert(String::from("links"), Value::Array(vec![])); - - Value::Table(imag_map) - }); - - Value::Table(m) - } - -} - -pub fn verify_header_consistency(t: Table) -> EntryResult { - verify_header(&t) - .map_err(Box::new) - .map_err(|e| ParserErrorKind::HeaderInconsistency.into_error_with_cause(e)) - .map(|_| t) -} - -fn verify_header(t: &Table) -> Result<()> { - if !has_main_section(t) { - Err(SE::from(ParserErrorKind::MissingMainSection.into_error())) - } else if !has_imag_version_in_main_section(t) { - Err(SE::from(ParserErrorKind::MissingVersionInfo.into_error())) - } else if !has_only_tables(t) { - debug!("Could not verify that it only has tables in its base table"); - Err(SE::from(ParserErrorKind::NonTableInBaseTable.into_error())) - } else { - Ok(()) - } -} - -fn has_only_tables(t: &Table) -> bool { - debug!("Verifying that table has only tables"); - t.iter().all(|(_, x)| is_match!(*x, Value::Table(_))) -} - -pub fn has_main_section(t: &Table) -> bool { - t.contains_key("imag") && is_match!(t.get("imag"), Some(&Value::Table(_))) -} - -pub fn has_imag_version_in_main_section(t: &Table) -> bool { - use semver::Version; - - match *t.get("imag").unwrap() { - Value::Table(ref sec) => { - sec.get("version") - .and_then(|v| { - match *v { - Value::String(ref s) => Some(Version::parse(&s[..]).is_ok()), - _ => Some(false), - } - }) - .unwrap_or(false) - } - _ => false, - } -} - - #[cfg(test)] mod test { extern crate env_logger; diff --git a/lib/core/libimagstore/src/util.rs b/lib/core/libimagstore/src/util.rs index 51462ab1..97b7cb74 100644 --- a/lib/core/libimagstore/src/util.rs +++ b/lib/core/libimagstore/src/util.rs @@ -23,8 +23,8 @@ use toml::Value; use libimagerror::into::IntoError; use store::Result; +use store::Header; use error::StoreErrorKind as SEK; -use toml_ext::Header; #[cfg(feature = "early-panic")] #[macro_export] From 3024fefcb9d338919e0a3b5b1b90fb77d2313330 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Aug 2017 17:48:23 +0200 Subject: [PATCH 06/17] Remove toml_ext module --- lib/core/libimagstore/src/lib.rs | 1 - lib/core/libimagstore/src/store.rs | 20 +- lib/core/libimagstore/src/toml_ext.rs | 803 -------------------------- 3 files changed, 1 insertion(+), 823 deletions(-) delete mode 100644 lib/core/libimagstore/src/toml_ext.rs diff --git a/lib/core/libimagstore/src/lib.rs b/lib/core/libimagstore/src/lib.rs index ae205b83..c879e230 100644 --- a/lib/core/libimagstore/src/lib.rs +++ b/lib/core/libimagstore/src/lib.rs @@ -58,5 +58,4 @@ pub mod error; pub mod store; mod configuration; pub mod file_abstraction; -pub mod toml_ext; diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index aba0583d..af7e5aaf 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -42,7 +42,7 @@ use error::{StoreError as SE, StoreErrorKind as SEK, ParserError, ParserErrorKin use error::MapErrInto; use storeid::{IntoStoreId, StoreId, StoreIdIterator}; use file_abstraction::FileAbstractionInstance; -use toml_ext::*; + // We re-export the following things so tests can use them pub use file_abstraction::FileAbstraction; pub use file_abstraction::FSFileAbstraction; @@ -1222,8 +1222,6 @@ mod test { #[test] fn test_imag_section() { - use toml_ext::has_main_section; - let mut map = BTreeMap::new(); map.insert("imag".into(), Value::Table(BTreeMap::new())); @@ -1232,8 +1230,6 @@ mod test { #[test] fn test_imag_invalid_section_type() { - use toml_ext::has_main_section; - let mut map = BTreeMap::new(); map.insert("imag".into(), Value::Boolean(false)); @@ -1242,8 +1238,6 @@ mod test { #[test] fn test_imag_abscent_main_section() { - use toml_ext::has_main_section; - let mut map = BTreeMap::new(); map.insert("not_imag".into(), Value::Boolean(false)); @@ -1252,8 +1246,6 @@ mod test { #[test] fn test_main_section_without_version() { - use toml_ext::has_imag_version_in_main_section; - let mut map = BTreeMap::new(); map.insert("imag".into(), Value::Table(BTreeMap::new())); @@ -1262,8 +1254,6 @@ mod test { #[test] fn test_main_section_with_version() { - use toml_ext::has_imag_version_in_main_section; - let mut map = BTreeMap::new(); let mut sub = BTreeMap::new(); sub.insert("version".into(), Value::String("0.0.0".into())); @@ -1274,8 +1264,6 @@ mod test { #[test] fn test_main_section_with_version_in_wrong_type() { - use toml_ext::has_imag_version_in_main_section; - let mut map = BTreeMap::new(); let mut sub = BTreeMap::new(); sub.insert("version".into(), Value::Boolean(false)); @@ -1286,8 +1274,6 @@ mod test { #[test] fn test_verification_good() { - use toml_ext::verify_header_consistency; - let mut header = BTreeMap::new(); let sub = { let mut sub = BTreeMap::new(); @@ -1303,8 +1289,6 @@ mod test { #[test] fn test_verification_invalid_versionstring() { - use toml_ext::verify_header_consistency; - let mut header = BTreeMap::new(); let sub = { let mut sub = BTreeMap::new(); @@ -1321,8 +1305,6 @@ mod test { #[test] fn test_verification_current_version() { - use toml_ext::verify_header_consistency; - let mut header = BTreeMap::new(); let sub = { let mut sub = BTreeMap::new(); diff --git a/lib/core/libimagstore/src/toml_ext.rs b/lib/core/libimagstore/src/toml_ext.rs deleted file mode 100644 index 1e51ffd8..00000000 --- a/lib/core/libimagstore/src/toml_ext.rs +++ /dev/null @@ -1,803 +0,0 @@ -// -// imag - the personal information management suite for the commandline -// Copyright (C) 2015, 2016 Matthias Beyer and contributors -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; version -// 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// - -use std::result::Result as RResult; -use std::collections::BTreeMap; - -use toml::Value; - -use store::Result; -use error::StoreError as SE; -use error::StoreErrorKind as SEK; -use error::{ParserErrorKind, ParserError}; -use libimagerror::into::IntoError; - -type Table = BTreeMap; - -pub trait TomlValueExt { - fn insert_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result; - fn set_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result>; - fn read_with_sep(&self, spec: &str, splitchr: char) -> Result>; - fn delete_with_sep(&mut self, spec: &str, splitchr: char) -> Result>; - - #[inline] - fn insert(&mut self, spec: &str, v: Value) -> Result { - self.insert_with_sep(spec, '.', v) - } - - #[inline] - fn set(&mut self, spec: &str, v: Value) -> Result> { - self.set_with_sep(spec, '.', v) - } - - #[inline] - fn read(&self, spec: &str) -> Result> { - self.read_with_sep(spec, '.') - } - - #[inline] - fn delete(&mut self, spec: &str) -> Result> { - self.delete_with_sep(spec, '.') - } -} - -#[derive(Debug, Clone, PartialEq, Eq)] -enum Token { - Key(String), - Index(usize), -} - -impl TomlValueExt for Value { - /** - * Insert a header field by a string-spec - * - * ```ignore - * insert("something.in.a.field", Boolean(true)); - * ``` - * - * If an array field was accessed which is _out of bounds_ of the array available, the element - * is appended to the array. - * - * Inserts a Boolean in the section "something" -> "in" -> "a" -> "field" - * A JSON equivalent would be - * - * { - * something: { - * in: { - * a: { - * field: true - * } - * } - * } - * } - * - * Returns true if header field was set, false if there is already a value - */ - fn insert_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result { - let (destination, value) = try!(setup(self, spec, sep)); - - // There is already an value at this place - if value.extract(&destination).is_ok() { - return Ok(false); - } - - match destination { - // if the destination shall be an map key - Token::Key(ref s) => match *value { - /* - * Put it in there if we have a map - */ - Value::Table(ref mut t) => { t.insert(s.clone(), v); }, - - /* - * Fail if there is no map here - */ - _ => return Err(SEK::HeaderPathTypeFailure.into_error()), - }, - - // if the destination shall be an array - Token::Index(i) => match *value { - - /* - * Put it in there if we have an array - */ - Value::Array(ref mut a) => { - a.push(v); // push to the end of the array - - // if the index is inside the array, we swap-remove the element at this - // index - if a.len() < i { - a.swap_remove(i); - } - }, - - /* - * Fail if there is no array here - */ - _ => return Err(SEK::HeaderPathTypeFailure.into_error()), - }, - } - - Ok(true) - } - - /** - * Set a header field by a string-spec - * - * ```ignore - * set("something.in.a.field", Boolean(true)); - * ``` - * - * Sets a Boolean in the section "something" -> "in" -> "a" -> "field" - * A JSON equivalent would be - * - * { - * something: { - * in: { - * a: { - * field: true - * } - * } - * } - * } - * - * If there is already a value at this place, this value will be overridden and the old value - * will be returned - */ - fn set_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result> { - let (destination, value) = try!(setup(self, spec, sep)); - - match destination { - // if the destination shall be an map key->value - Token::Key(ref s) => match *value { - /* - * Put it in there if we have a map - */ - Value::Table(ref mut t) => { - debug!("Matched Key->Table"); - return Ok(t.insert(s.clone(), v)); - } - - /* - * Fail if there is no map here - */ - _ => { - debug!("Matched Key->NON-Table"); - return Err(SEK::HeaderPathTypeFailure.into_error()); - } - }, - - // if the destination shall be an array - Token::Index(i) => match *value { - - /* - * Put it in there if we have an array - */ - Value::Array(ref mut a) => { - debug!("Matched Index->Array"); - a.push(v); // push to the end of the array - - // if the index is inside the array, we swap-remove the element at this - // index - if a.len() > i { - debug!("Swap-Removing in Array {:?}[{:?}] <- {:?}", a, i, a[a.len()-1]); - return Ok(Some(a.swap_remove(i))); - } - - debug!("Appended"); - return Ok(None); - }, - - /* - * Fail if there is no array here - */ - _ => { - debug!("Matched Index->NON-Array"); - return Err(SEK::HeaderPathTypeFailure.into_error()); - }, - }, - } - } - - /** - * Read a header field by a string-spec - * - * ```ignore - * let value = read("something.in.a.field"); - * ``` - * - * Reads a Value in the section "something" -> "in" -> "a" -> "field" - * A JSON equivalent would be - * - * { - * something: { - * in: { - * a: { - * field: true - * } - * } - * } - * } - * - * If there is no a value at this place, None will be returned. This also holds true for Arrays - * which are accessed at an index which is not yet there, even if the accessed index is much - * larger than the array length. - */ - fn read_with_sep(&self, spec: &str, splitchr: char) -> Result> { - let tokens = try!(tokenize(spec, splitchr)); - - let mut header_clone = self.clone(); // we clone as READing is simpler this way - // walk N-1 tokens - match walk_header(&mut header_clone, tokens) { - Err(e) => match e.err_type() { - // We cannot find the header key, as there is no path to it - SEK::HeaderKeyNotFound => Ok(None), - _ => Err(e), - }, - Ok(v) => Ok(Some(v.clone())), - } - } - - fn delete_with_sep(&mut self, spec: &str, splitchr: char) -> Result> { - let (destination, value) = try!(setup(self, spec, splitchr)); - - match destination { - // if the destination shall be an map key->value - Token::Key(ref s) => match *value { - Value::Table(ref mut t) => { - debug!("Matched Key->Table, removing {:?}", s); - return Ok(t.remove(s)); - }, - _ => { - debug!("Matched Key->NON-Table"); - return Err(SEK::HeaderPathTypeFailure.into_error()); - } - }, - - // if the destination shall be an array - Token::Index(i) => match *value { - - // if the index is inside the array, we swap-remove the element at this - // index - Value::Array(ref mut a) => if a.len() > i { - debug!("Removing in Array {:?}[{:?}]", a, i); - return Ok(Some(a.remove(i))); - } else { - return Ok(None); - }, - _ => { - debug!("Matched Index->NON-Array"); - return Err(SEK::HeaderPathTypeFailure.into_error()); - }, - }, - } - } - -} - -fn setup<'a>(v: &'a mut Value, spec: &str, sep: char) - -> Result<(Token, &'a mut Value)> -{ - let tokens = try!(tokenize(spec, sep)); - debug!("tokens = {:?}", tokens); - - let destination = try!(tokens.iter().last().cloned().ok_or(SEK::HeaderPathSyntaxError.into_error())); - debug!("destination = {:?}", destination); - - let path_to_dest : Vec = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens - let value = try!(walk_header(v, path_to_dest)); // walk N-1 tokens - - debug!("walked value = {:?}", value); - - Ok((destination, value)) -} - -fn tokenize(spec: &str, splitchr: char) -> Result> { - use std::str::FromStr; - - spec.split(splitchr) - .map(|s| usize::from_str(s).map(Token::Index).or_else(|_| Ok(Token::Key(String::from(s))))) - .collect() -} - -fn walk_header(v: &mut Value, tokens: Vec) -> Result<&mut Value> { - use std::vec::IntoIter; - - fn walk_iter<'a>(v: Result<&'a mut Value>, i: &mut IntoIter) -> Result<&'a mut Value> { - let next = i.next(); - v.and_then(move |value| if let Some(token) = next { - walk_iter(value.extract(&token), i) - } else { - Ok(value) - }) - } - - walk_iter(Ok(v), &mut tokens.into_iter()) -} - -trait Extract { - fn extract<'a>(&'a mut self, &Token) -> Result<&'a mut Self>; -} - -impl Extract for Value { - fn extract<'a>(&'a mut self, token: &Token) -> Result<&'a mut Value> { - match *token { - // on Token::Key extract from Value::Table - Token::Key(ref s) => match *self { - Value::Table(ref mut t) => - t.get_mut(&s[..]).ok_or(SEK::HeaderKeyNotFound.into_error()), - - _ => Err(SEK::HeaderPathTypeFailure.into_error()), - }, - - // on Token::Index extract from Value::Array - Token::Index(i) => match *self { - Value::Array(ref mut a) => if a.len() < i { - Err(SEK::HeaderKeyNotFound.into_error()) - } else { - Ok(&mut a[i]) - }, - - _ => Err(SEK::HeaderPathTypeFailure.into_error()), - } - } - } -} - -pub type EntryResult = RResult; - -#[cfg(test)] -mod test { - extern crate env_logger; - use super::TomlValueExt; - use super::{tokenize, walk_header}; - use super::Token; - - use std::collections::BTreeMap; - - use toml::Value; - - #[test] - fn test_walk_header_simple() { - let tokens = tokenize("a", '.').unwrap(); - assert!(tokens.len() == 1, "1 token was expected, {} were parsed", tokens.len()); - assert!(tokens.iter().next().unwrap() == &Token::Key(String::from("a")), - "'a' token was expected, {:?} was parsed", tokens.iter().next()); - - let mut header = BTreeMap::new(); - header.insert(String::from("a"), Value::Integer(1)); - - let mut v_header = Value::Table(header); - let res = walk_header(&mut v_header, tokens); - assert_eq!(&mut Value::Integer(1), res.unwrap()); - } - - #[test] - fn test_walk_header_with_array() { - let tokens = tokenize("a.0", '.').unwrap(); - assert!(tokens.len() == 2, "2 token was expected, {} were parsed", tokens.len()); - assert!(tokens.iter().next().unwrap() == &Token::Key(String::from("a")), - "'a' token was expected, {:?} was parsed", tokens.iter().next()); - - let mut header = BTreeMap::new(); - let ary = Value::Array(vec![Value::Integer(1)]); - header.insert(String::from("a"), ary); - - - let mut v_header = Value::Table(header); - let res = walk_header(&mut v_header, tokens); - assert_eq!(&mut Value::Integer(1), res.unwrap()); - } - - #[test] - fn test_walk_header_extract_array() { - let tokens = tokenize("a", '.').unwrap(); - assert!(tokens.len() == 1, "1 token was expected, {} were parsed", tokens.len()); - assert!(tokens.iter().next().unwrap() == &Token::Key(String::from("a")), - "'a' token was expected, {:?} was parsed", tokens.iter().next()); - - let mut header = BTreeMap::new(); - let ary = Value::Array(vec![Value::Integer(1)]); - header.insert(String::from("a"), ary); - - let mut v_header = Value::Table(header); - let res = walk_header(&mut v_header, tokens); - assert_eq!(&mut Value::Array(vec![Value::Integer(1)]), res.unwrap()); - } - - /** - * Creates a big testing header. - * - * JSON equivalent: - * - * ```json - * { - * "a": { - * "array": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] - * }, - * "b": { - * "array": [ "string1", "string2", "string3", "string4" ] - * }, - * "c": { - * "array": [ 1, "string2", 3, "string4" ] - * }, - * "d": { - * "array": [ - * { - * "d1": 1 - * }, - * { - * "d2": 2 - * }, - * { - * "d3": 3 - * }, - * ], - * - * "something": "else", - * - * "and": { - * "something": { - * "totally": "different" - * } - * } - * } - * } - * ``` - * - * The sections "a", "b", "c", "d" are created in the respective helper functions - * create_header_section_a, create_header_section_b, create_header_section_c and - * create_header_section_d. - * - * These functions can also be used for testing. - * - */ - fn create_header() -> Value { - let a = create_header_section_a(); - let b = create_header_section_b(); - let c = create_header_section_c(); - let d = create_header_section_d(); - - let mut header = BTreeMap::new(); - header.insert(String::from("a"), a); - header.insert(String::from("b"), b); - header.insert(String::from("c"), c); - header.insert(String::from("d"), d); - - Value::Table(header) - } - - fn create_header_section_a() -> Value { - // 0..10 is exclusive 10 - let a_ary = Value::Array((0..10).map(|x| Value::Integer(x)).collect()); - - let mut a_obj = BTreeMap::new(); - a_obj.insert(String::from("array"), a_ary); - Value::Table(a_obj) - } - - fn create_header_section_b() -> Value { - let b_ary = Value::Array((0..9) - .map(|x| Value::String(format!("string{}", x))) - .collect()); - - let mut b_obj = BTreeMap::new(); - b_obj.insert(String::from("array"), b_ary); - Value::Table(b_obj) - } - - fn create_header_section_c() -> Value { - let c_ary = Value::Array( - vec![ - Value::Integer(1), - Value::String(String::from("string2")), - Value::Integer(3), - Value::String(String::from("string4")) - ]); - - let mut c_obj = BTreeMap::new(); - c_obj.insert(String::from("array"), c_ary); - Value::Table(c_obj) - } - - fn create_header_section_d() -> Value { - let d_ary = Value::Array( - vec![ - { - let mut tab = BTreeMap::new(); - tab.insert(String::from("d1"), Value::Integer(1)); - tab - }, - { - let mut tab = BTreeMap::new(); - tab.insert(String::from("d2"), Value::Integer(2)); - tab - }, - { - let mut tab = BTreeMap::new(); - tab.insert(String::from("d3"), Value::Integer(3)); - tab - }, - ].into_iter().map(Value::Table).collect()); - - let and_obj = Value::Table({ - let mut tab = BTreeMap::new(); - let something_tab = Value::Table({ - let mut tab = BTreeMap::new(); - tab.insert(String::from("totally"), Value::String(String::from("different"))); - tab - }); - tab.insert(String::from("something"), something_tab); - tab - }); - - let mut d_obj = BTreeMap::new(); - d_obj.insert(String::from("array"), d_ary); - d_obj.insert(String::from("something"), Value::String(String::from("else"))); - d_obj.insert(String::from("and"), and_obj); - Value::Table(d_obj) - } - - #[test] - fn test_walk_header_big_a() { - test_walk_header_extract_section("a", &create_header_section_a()); - } - - #[test] - fn test_walk_header_big_b() { - test_walk_header_extract_section("b", &create_header_section_b()); - } - - #[test] - fn test_walk_header_big_c() { - test_walk_header_extract_section("c", &create_header_section_c()); - } - - #[test] - fn test_walk_header_big_d() { - test_walk_header_extract_section("d", &create_header_section_d()); - } - - fn test_walk_header_extract_section(secname: &str, expected: &Value) { - let tokens = tokenize(secname, '.').unwrap(); - assert!(tokens.len() == 1, "1 token was expected, {} were parsed", tokens.len()); - assert!(tokens.iter().next().unwrap() == &Token::Key(String::from(secname)), - "'{}' token was expected, {:?} was parsed", secname, tokens.iter().next()); - - let mut header = create_header(); - let res = walk_header(&mut header, tokens); - assert_eq!(expected, res.unwrap()); - } - - #[test] - fn test_walk_header_extract_numbers() { - test_extract_number("a", 0, 0); - test_extract_number("a", 1, 1); - test_extract_number("a", 2, 2); - test_extract_number("a", 3, 3); - test_extract_number("a", 4, 4); - test_extract_number("a", 5, 5); - test_extract_number("a", 6, 6); - test_extract_number("a", 7, 7); - test_extract_number("a", 8, 8); - test_extract_number("a", 9, 9); - - test_extract_number("c", 0, 1); - test_extract_number("c", 2, 3); - } - - fn test_extract_number(sec: &str, idx: usize, exp: i64) { - let tokens = tokenize(&format!("{}.array.{}", sec, idx)[..], '.').unwrap(); - assert!(tokens.len() == 3, "3 token was expected, {} were parsed", tokens.len()); - { - let mut iter = tokens.iter(); - - let tok = iter.next().unwrap(); - let exp = Token::Key(String::from(sec)); - assert!(tok == &exp, "'{}' token was expected, {:?} was parsed", sec, tok); - - let tok = iter.next().unwrap(); - let exp = Token::Key(String::from("array")); - assert!(tok == &exp, "'array' token was expected, {:?} was parsed", tok); - - let tok = iter.next().unwrap(); - let exp = Token::Index(idx); - assert!(tok == &exp, "'{}' token was expected, {:?} was parsed", idx, tok); - } - - let mut header = create_header(); - let res = walk_header(&mut header, tokens); - assert_eq!(&mut Value::Integer(exp), res.unwrap()); - } - - #[test] - fn test_header_read() { - let h = create_header(); - - assert!(if let Ok(Some(Value::Table(_))) = h.read("a") { true } else { false }); - assert!(if let Ok(Some(Value::Array(_))) = h.read("a.array") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("a.array.1") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("a.array.9") { true } else { false }); - - assert!(if let Ok(Some(Value::Table(_))) = h.read("c") { true } else { false }); - assert!(if let Ok(Some(Value::Array(_))) = h.read("c.array") { true } else { false }); - assert!(if let Ok(Some(Value::String(_))) = h.read("c.array.1") { true } else { false }); - assert!(if let Ok(None) = h.read("c.array.9") { true } else { false }); - - assert!(if let Ok(Some(Value::Integer(_))) = h.read("d.array.0.d1") { true } else { false }); - assert!(if let Ok(None) = h.read("d.array.0.d2") { true } else { false }); - assert!(if let Ok(None) = h.read("d.array.0.d3") { true } else { false }); - - assert!(if let Ok(None) = h.read("d.array.1.d1") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("d.array.1.d2") { true } else { false }); - assert!(if let Ok(None) = h.read("d.array.1.d3") { true } else { false }); - - assert!(if let Ok(None) = h.read("d.array.2.d1") { true } else { false }); - assert!(if let Ok(None) = h.read("d.array.2.d2") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("d.array.2.d3") { true } else { false }); - - assert!(if let Ok(Some(Value::String(_))) = h.read("d.something") { true } else { false }); - assert!(if let Ok(Some(Value::Table(_))) = h.read("d.and") { true } else { false }); - assert!(if let Ok(Some(Value::Table(_))) = h.read("d.and.something") { true } else { false }); - assert!(if let Ok(Some(Value::String(_))) = h.read("d.and.something.totally") { true } else { false }); - } - - #[test] - fn test_header_set_override() { - let _ = env_logger::init(); - let mut h = create_header(); - - println!("Testing index 0"); - assert_eq!(h.read("a.array.0").unwrap().unwrap(), Value::Integer(0)); - - println!("Altering index 0"); - assert_eq!(h.set("a.array.0", Value::Integer(42)).unwrap().unwrap(), Value::Integer(0)); - - println!("Values now: {:?}", h); - - println!("Testing all indexes"); - assert_eq!(h.read("a.array.0").unwrap().unwrap(), Value::Integer(42)); - assert_eq!(h.read("a.array.1").unwrap().unwrap(), Value::Integer(1)); - assert_eq!(h.read("a.array.2").unwrap().unwrap(), Value::Integer(2)); - assert_eq!(h.read("a.array.3").unwrap().unwrap(), Value::Integer(3)); - assert_eq!(h.read("a.array.4").unwrap().unwrap(), Value::Integer(4)); - assert_eq!(h.read("a.array.5").unwrap().unwrap(), Value::Integer(5)); - assert_eq!(h.read("a.array.6").unwrap().unwrap(), Value::Integer(6)); - assert_eq!(h.read("a.array.7").unwrap().unwrap(), Value::Integer(7)); - assert_eq!(h.read("a.array.8").unwrap().unwrap(), Value::Integer(8)); - assert_eq!(h.read("a.array.9").unwrap().unwrap(), Value::Integer(9)); - } - - #[test] - fn test_header_set_new() { - let _ = env_logger::init(); - let mut h = create_header(); - - assert!(h.read("a.foo").is_ok()); - assert!(h.read("a.foo").unwrap().is_none()); - - { - let v = h.set("a.foo", Value::Integer(42)); - assert!(v.is_ok()); - assert!(v.unwrap().is_none()); - - assert!(if let Ok(Some(Value::Table(_))) = h.read("a") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("a.foo") { true } else { false }); - } - - { - let v = h.set("new", Value::Table(BTreeMap::new())); - assert!(v.is_ok()); - assert!(v.unwrap().is_none()); - - let v = h.set("new.subset", Value::Table(BTreeMap::new())); - assert!(v.is_ok()); - assert!(v.unwrap().is_none()); - - let v = h.set("new.subset.dest", Value::Integer(1337)); - assert!(v.is_ok()); - assert!(v.unwrap().is_none()); - - assert!(if let Ok(Some(Value::Table(_))) = h.read("new") { true } else { false }); - assert!(if let Ok(Some(Value::Table(_))) = h.read("new.subset") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("new.subset.dest") { true } else { false }); - } - } - - - #[test] - fn test_header_insert_override() { - let _ = env_logger::init(); - let mut h = create_header(); - - println!("Testing index 0"); - assert_eq!(h.read("a.array.0").unwrap().unwrap(), Value::Integer(0)); - - println!("Altering index 0"); - assert_eq!(h.insert("a.array.0", Value::Integer(42)).unwrap(), false); - println!("...should have failed"); - - println!("Testing all indexes"); - assert_eq!(h.read("a.array.0").unwrap().unwrap(), Value::Integer(0)); - assert_eq!(h.read("a.array.1").unwrap().unwrap(), Value::Integer(1)); - assert_eq!(h.read("a.array.2").unwrap().unwrap(), Value::Integer(2)); - assert_eq!(h.read("a.array.3").unwrap().unwrap(), Value::Integer(3)); - assert_eq!(h.read("a.array.4").unwrap().unwrap(), Value::Integer(4)); - assert_eq!(h.read("a.array.5").unwrap().unwrap(), Value::Integer(5)); - assert_eq!(h.read("a.array.6").unwrap().unwrap(), Value::Integer(6)); - assert_eq!(h.read("a.array.7").unwrap().unwrap(), Value::Integer(7)); - assert_eq!(h.read("a.array.8").unwrap().unwrap(), Value::Integer(8)); - assert_eq!(h.read("a.array.9").unwrap().unwrap(), Value::Integer(9)); - } - - #[test] - fn test_header_insert_new() { - let _ = env_logger::init(); - let mut h = create_header(); - - assert!(h.read("a.foo").is_ok()); - assert!(h.read("a.foo").unwrap().is_none()); - - { - let v = h.insert("a.foo", Value::Integer(42)); - assert!(v.is_ok()); - assert_eq!(v.unwrap(), true); - - assert!(if let Ok(Some(Value::Table(_))) = h.read("a") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("a.foo") { true } else { false }); - } - - { - let v = h.insert("new", Value::Table(BTreeMap::new())); - assert!(v.is_ok()); - assert_eq!(v.unwrap(), true); - - let v = h.insert("new.subset", Value::Table(BTreeMap::new())); - assert!(v.is_ok()); - assert_eq!(v.unwrap(), true); - - let v = h.insert("new.subset.dest", Value::Integer(1337)); - assert!(v.is_ok()); - assert_eq!(v.unwrap(), true); - - assert!(if let Ok(Some(Value::Table(_))) = h.read("new") { true } else { false }); - assert!(if let Ok(Some(Value::Table(_))) = h.read("new.subset") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("new.subset.dest") { true } else { false }); - } - } - - #[test] - fn test_header_delete() { - let _ = env_logger::init(); - let mut h = create_header(); - - assert!(if let Ok(Some(Value::Table(_))) = h.read("a") { true } else { false }); - assert!(if let Ok(Some(Value::Array(_))) = h.read("a.array") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("a.array.1") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(_))) = h.read("a.array.9") { true } else { false }); - - assert!(if let Ok(Some(Value::Integer(1))) = h.delete("a.array.1") { true } else { false }); - assert!(if let Ok(Some(Value::Integer(9))) = h.delete("a.array.8") { true } else { false }); - assert!(if let Ok(Some(Value::Array(_))) = h.delete("a.array") { true } else { false }); - assert!(if let Ok(Some(Value::Table(_))) = h.delete("a") { true } else { false }); - - } - -} - From c0c62bd1b5c5b9ece1d8289721dc8617987a7885 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Aug 2017 17:53:08 +0200 Subject: [PATCH 07/17] 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 + .../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(-) 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,10 +18,11 @@ // use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; + +use toml_query::read::TomlValueReadExt; +use filters::filter::Filter; use builtin::header::field_path::FieldPath; -use filters::filter::Filter; 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!() } })) From ae5255c7c7ed7c40c44240218b957be383ad698d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 29 Aug 2017 17:21:52 +0200 Subject: [PATCH 08/17] Remove unused crate imports This patch removes unused crate imports reported by newer rust versions. Some crates were only required for tests, some only for tests with macro_import - these things were fixed with feature gates. --- bin/core/imag-link/Cargo.toml | 5 ++--- bin/core/imag-link/src/main.rs | 5 ++--- bin/core/imag-ref/Cargo.toml | 2 -- bin/core/imag-ref/src/main.rs | 2 -- bin/core/imag-store/Cargo.toml | 1 - bin/core/imag-store/src/main.rs | 1 - bin/core/imag-tag/Cargo.toml | 3 +-- bin/core/imag-tag/src/main.rs | 4 ++-- bin/core/imag-view/Cargo.toml | 2 -- bin/core/imag-view/src/main.rs | 2 -- bin/domain/imag-bookmark/Cargo.toml | 1 - bin/domain/imag-bookmark/src/main.rs | 1 - bin/domain/imag-mail/Cargo.toml | 3 --- bin/domain/imag-mail/src/main.rs | 3 --- bin/domain/imag-notes/Cargo.toml | 1 - bin/domain/imag-notes/src/main.rs | 1 - bin/domain/imag-timetrack/Cargo.toml | 3 --- bin/domain/imag-timetrack/src/main.rs | 3 --- bin/domain/imag-todo/Cargo.toml | 5 ----- bin/domain/imag-todo/src/main.rs | 6 ------ lib/core/libimagrt/Cargo.toml | 1 - lib/core/libimagrt/src/lib.rs | 1 - lib/core/libimagstore/Cargo.toml | 3 --- lib/core/libimagstore/src/lib.rs | 4 ---- lib/domain/libimagbookmark/Cargo.toml | 1 - lib/domain/libimagbookmark/src/lib.rs | 1 - lib/domain/libimagcounter/Cargo.toml | 1 - lib/domain/libimagcounter/src/lib.rs | 1 - lib/domain/libimagdiary/Cargo.toml | 3 --- lib/domain/libimagdiary/src/lib.rs | 3 --- lib/domain/libimagmail/Cargo.toml | 2 -- lib/domain/libimagmail/src/lib.rs | 2 -- lib/domain/libimagnotes/Cargo.toml | 2 -- lib/domain/libimagnotes/src/lib.rs | 2 -- lib/domain/libimagtodo/Cargo.toml | 3 --- lib/domain/libimagtodo/src/lib.rs | 3 --- lib/entry/libimagentryannotation/Cargo.toml | 2 -- lib/entry/libimagentryannotation/src/lib.rs | 2 -- lib/entry/libimagentrydatetime/Cargo.toml | 1 - lib/entry/libimagentrydatetime/src/lib.rs | 1 - lib/entry/libimagentryfilter/src/lib.rs | 1 - lib/entry/libimagentrylink/Cargo.toml | 1 - lib/entry/libimagentrylink/src/lib.rs | 1 - lib/entry/libimagentrylist/Cargo.toml | 1 - lib/entry/libimagentrylist/src/lib.rs | 1 - lib/entry/libimagentrymarkdown/Cargo.toml | 1 - lib/entry/libimagentrymarkdown/src/lib.rs | 1 - lib/entry/libimagentryref/Cargo.toml | 3 --- lib/entry/libimagentryref/src/lib.rs | 3 --- lib/entry/libimagentrytag/Cargo.toml | 1 - lib/entry/libimagentrytag/src/lib.rs | 1 - lib/entry/libimagentryview/Cargo.toml | 1 - lib/entry/libimagentryview/src/lib.rs | 1 - lib/etc/libimaginteraction/Cargo.toml | 4 ---- lib/etc/libimaginteraction/src/lib.rs | 4 ---- 55 files changed, 7 insertions(+), 111 deletions(-) diff --git a/bin/core/imag-link/Cargo.toml b/bin/core/imag-link/Cargo.toml index 7b2c1884..c73ec329 100644 --- a/bin/core/imag-link/Cargo.toml +++ b/bin/core/imag-link/Cargo.toml @@ -14,13 +14,12 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -semver = "0.5.1" clap = ">=2.17" log = "0.3" version = "2.0.1" -toml = "^0.4" -toml-query = "0.1" url = "1.2" +toml = "0.4" +toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs index 45c08325..6e3a92b8 100644 --- a/bin/core/imag-link/src/main.rs +++ b/bin/core/imag-link/src/main.rs @@ -34,11 +34,10 @@ #[macro_use] extern crate log; extern crate clap; -extern crate semver; -extern crate toml; -extern crate toml_query; extern crate url; #[macro_use] extern crate version; +#[cfg(test)] extern crate toml; +#[cfg(test)] extern crate toml_query; extern crate libimagentrylink; extern crate libimagrt; diff --git a/bin/core/imag-ref/Cargo.toml b/bin/core/imag-ref/Cargo.toml index d2e92b19..1d93a042 100644 --- a/bin/core/imag-ref/Cargo.toml +++ b/bin/core/imag-ref/Cargo.toml @@ -14,12 +14,10 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -semver = "0.5.1" clap = ">=2.17" log = "0.3" version = "2.0.1" -libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagentryref = { version = "0.4.0", path = "../../../lib/entry/libimagentryref" } diff --git a/bin/core/imag-ref/src/main.rs b/bin/core/imag-ref/src/main.rs index aa2f7d08..092ca762 100644 --- a/bin/core/imag-ref/src/main.rs +++ b/bin/core/imag-ref/src/main.rs @@ -34,10 +34,8 @@ #[macro_use] extern crate log; #[macro_use] extern crate version; -extern crate semver; extern crate clap; -extern crate libimagstore; extern crate libimagrt; extern crate libimagentryref; extern crate libimagerror; diff --git a/bin/core/imag-store/Cargo.toml b/bin/core/imag-store/Cargo.toml index d2e47410..34a54b92 100644 --- a/bin/core/imag-store/Cargo.toml +++ b/bin/core/imag-store/Cargo.toml @@ -17,7 +17,6 @@ homepage = "http://imag-pim.org" clap = ">=2.17" log = "0.3" version = "2.0.1" -semver = "0.5" toml = "^0.4" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore", features = ["verify"] } diff --git a/bin/core/imag-store/src/main.rs b/bin/core/imag-store/src/main.rs index c425bf7b..9e5c5267 100644 --- a/bin/core/imag-store/src/main.rs +++ b/bin/core/imag-store/src/main.rs @@ -34,7 +34,6 @@ extern crate clap; #[macro_use] extern crate log; -extern crate semver; extern crate toml; #[macro_use] extern crate version; diff --git a/bin/core/imag-tag/Cargo.toml b/bin/core/imag-tag/Cargo.toml index afd41e61..0e53a1c0 100644 --- a/bin/core/imag-tag/Cargo.toml +++ b/bin/core/imag-tag/Cargo.toml @@ -17,8 +17,7 @@ homepage = "http://imag-pim.org" clap = "2.*" log = "0.3" version = "2.0.1" -semver = "0.2" -toml = "^0.4" +toml = "0.4" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-tag/src/main.rs b/bin/core/imag-tag/src/main.rs index c4f7eb3f..882a4053 100644 --- a/bin/core/imag-tag/src/main.rs +++ b/bin/core/imag-tag/src/main.rs @@ -19,10 +19,10 @@ extern crate clap; #[macro_use] extern crate log; -extern crate semver; -extern crate toml; #[macro_use] extern crate version; +#[cfg(test)] extern crate toml; + extern crate libimagstore; extern crate libimagrt; extern crate libimagentrytag; diff --git a/bin/core/imag-view/Cargo.toml b/bin/core/imag-view/Cargo.toml index ad4456a9..ed69c44c 100644 --- a/bin/core/imag-view/Cargo.toml +++ b/bin/core/imag-view/Cargo.toml @@ -16,8 +16,6 @@ homepage = "http://imag-pim.org" [dependencies] clap = ">=2.17" log = "0.3" -semver = "0.5" -toml = "^0.4" version = "2.0.1" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-view/src/main.rs b/bin/core/imag-view/src/main.rs index da20fa54..e6b78092 100644 --- a/bin/core/imag-view/src/main.rs +++ b/bin/core/imag-view/src/main.rs @@ -34,8 +34,6 @@ extern crate clap; #[macro_use] extern crate log; -extern crate semver; -extern crate toml; #[macro_use] extern crate version; extern crate libimagentryview; diff --git a/bin/domain/imag-bookmark/Cargo.toml b/bin/domain/imag-bookmark/Cargo.toml index 658566d3..3ab2a245 100644 --- a/bin/domain/imag-bookmark/Cargo.toml +++ b/bin/domain/imag-bookmark/Cargo.toml @@ -21,6 +21,5 @@ version = "2.0.1" libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagbookmark = { version = "0.4.0", path = "../../../lib/domain/libimagbookmark" } -libimagentrylink = { version = "0.4.0", path = "../../../lib/entry/libimagentrylink" } libimagentrytag = { version = "0.4.0", path = "../../../lib/entry/libimagentrytag" } libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } diff --git a/bin/domain/imag-bookmark/src/main.rs b/bin/domain/imag-bookmark/src/main.rs index e0635164..43924e73 100644 --- a/bin/domain/imag-bookmark/src/main.rs +++ b/bin/domain/imag-bookmark/src/main.rs @@ -37,7 +37,6 @@ extern crate clap; #[macro_use] extern crate version; extern crate libimagbookmark; -extern crate libimagentrylink; extern crate libimagentrytag; extern crate libimagrt; extern crate libimagerror; diff --git a/bin/domain/imag-mail/Cargo.toml b/bin/domain/imag-mail/Cargo.toml index 8c9dfbc5..ac69c58c 100644 --- a/bin/domain/imag-mail/Cargo.toml +++ b/bin/domain/imag-mail/Cargo.toml @@ -10,12 +10,9 @@ readme = "../README.md" license = "LGPL-2.1" [dependencies] -semver = "0.5" clap = "2.*" log = "0.3" version = "2.0.1" -toml = "0.4.*" -url = "1.2" libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } diff --git a/bin/domain/imag-mail/src/main.rs b/bin/domain/imag-mail/src/main.rs index 1eeb52bf..cb910630 100644 --- a/bin/domain/imag-mail/src/main.rs +++ b/bin/domain/imag-mail/src/main.rs @@ -17,10 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -extern crate semver; extern crate clap; -extern crate toml; -extern crate url; #[macro_use] extern crate log; #[macro_use] extern crate version; diff --git a/bin/domain/imag-notes/Cargo.toml b/bin/domain/imag-notes/Cargo.toml index e274e3d8..6228662c 100644 --- a/bin/domain/imag-notes/Cargo.toml +++ b/bin/domain/imag-notes/Cargo.toml @@ -14,7 +14,6 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -semver = "0.2.1" clap = ">=2.17" log = "0.3" version = "2.0.1" diff --git a/bin/domain/imag-notes/src/main.rs b/bin/domain/imag-notes/src/main.rs index 697c034d..5d07f5b7 100644 --- a/bin/domain/imag-notes/src/main.rs +++ b/bin/domain/imag-notes/src/main.rs @@ -19,7 +19,6 @@ extern crate clap; #[macro_use] extern crate log; -extern crate semver; #[macro_use] extern crate version; extern crate itertools; diff --git a/bin/domain/imag-timetrack/Cargo.toml b/bin/domain/imag-timetrack/Cargo.toml index 21b394bc..27d68595 100644 --- a/bin/domain/imag-timetrack/Cargo.toml +++ b/bin/domain/imag-timetrack/Cargo.toml @@ -17,8 +17,6 @@ homepage = "http://imag-pim.org" clap = "2.*" log = "0.3" version = "2.0.1" -semver = "0.2" -toml = "^0.4" chrono = "^0.4" filters = "0.1.1" itertools = "0.6" @@ -27,4 +25,3 @@ libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagtimetrack = { version = "0.4.0", path = "../../../lib/domain/libimagtimetrack" } -libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } diff --git a/bin/domain/imag-timetrack/src/main.rs b/bin/domain/imag-timetrack/src/main.rs index 7fc53bfa..85e270a6 100644 --- a/bin/domain/imag-timetrack/src/main.rs +++ b/bin/domain/imag-timetrack/src/main.rs @@ -24,8 +24,6 @@ extern crate log; extern crate version; extern crate clap; -extern crate semver; -extern crate toml; extern crate chrono; extern crate filters; extern crate itertools; @@ -34,7 +32,6 @@ extern crate libimagerror; extern crate libimagstore; extern crate libimagrt; extern crate libimagtimetrack; -extern crate libimagutil; mod cont; mod day; diff --git a/bin/domain/imag-todo/Cargo.toml b/bin/domain/imag-todo/Cargo.toml index 047cdd50..a2c1503d 100644 --- a/bin/domain/imag-todo/Cargo.toml +++ b/bin/domain/imag-todo/Cargo.toml @@ -15,17 +15,12 @@ homepage = "http://imag-pim.org" [dependencies] clap = ">=2.17" -glob = "0.2.11" log = "0.3.6" -semver = "0.5.1" -serde_json = "0.8.3" -task-hookrs = "0.2.2" toml = "0.4.*" toml-query = "0.3.*" is-match = "0.1.*" version = "2.0.1" libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } -libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagtodo = { version = "0.4.0", path = "../../../lib/domain/libimagtodo" } diff --git a/bin/domain/imag-todo/src/main.rs b/bin/domain/imag-todo/src/main.rs index b9bd8872..43545d2a 100644 --- a/bin/domain/imag-todo/src/main.rs +++ b/bin/domain/imag-todo/src/main.rs @@ -18,19 +18,13 @@ // extern crate clap; -extern crate glob; #[macro_use] extern crate log; -extern crate serde_json; -extern crate semver; extern crate toml; extern crate toml_query; #[macro_use] extern crate is_match; #[macro_use] extern crate version; -extern crate task_hookrs; - extern crate libimagrt; -extern crate libimagstore; extern crate libimagerror; extern crate libimagtodo; diff --git a/lib/core/libimagrt/Cargo.toml b/lib/core/libimagrt/Cargo.toml index 0599e233..c717580c 100644 --- a/lib/core/libimagrt/Cargo.toml +++ b/lib/core/libimagrt/Cargo.toml @@ -20,7 +20,6 @@ toml = "^0.4" log = "0.3" xdg-basedir = "1.0" itertools = "0.5" -tempfile = "2.1" ansi_term = "0.9" is-match = "0.1" toml-query = "0.3.0" diff --git a/lib/core/libimagrt/src/lib.rs b/lib/core/libimagrt/src/lib.rs index a28b525f..ce0e08c1 100644 --- a/lib/core/libimagrt/src/lib.rs +++ b/lib/core/libimagrt/src/lib.rs @@ -37,7 +37,6 @@ extern crate itertools; #[cfg(unix)] extern crate xdg_basedir; extern crate env_logger; -extern crate tempfile; extern crate ansi_term; extern crate clap; diff --git a/lib/core/libimagstore/Cargo.toml b/lib/core/libimagstore/Cargo.toml index c5fb527f..a904e0b3 100644 --- a/lib/core/libimagstore/Cargo.toml +++ b/lib/core/libimagstore/Cargo.toml @@ -14,7 +14,6 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -fs2 = "0.4" glob = "0.2.11" lazy_static = "0.2.*" log = "0.3" @@ -22,9 +21,7 @@ regex = "0.2" semver = "0.5" toml = "^0.4" version = "2.0.1" -crossbeam = "0.2.*" walkdir = "1.0.*" -itertools = "0.6.*" is-match = "0.1" serde = "1.0" serde_json = "1.0" diff --git a/lib/core/libimagstore/src/lib.rs b/lib/core/libimagstore/src/lib.rs index ba9abe83..96147ef2 100644 --- a/lib/core/libimagstore/src/lib.rs +++ b/lib/core/libimagstore/src/lib.rs @@ -35,18 +35,14 @@ #[macro_use] extern crate log; #[macro_use] extern crate version; -extern crate fs2; extern crate glob; #[macro_use] extern crate lazy_static; extern crate regex; extern crate toml; #[cfg(test)] extern crate tempdir; extern crate semver; -extern crate crossbeam; extern crate walkdir; -extern crate itertools; #[macro_use] extern crate is_match; -extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; diff --git a/lib/domain/libimagbookmark/Cargo.toml b/lib/domain/libimagbookmark/Cargo.toml index d81cb9d8..4b621b5a 100644 --- a/lib/domain/libimagbookmark/Cargo.toml +++ b/lib/domain/libimagbookmark/Cargo.toml @@ -14,7 +14,6 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -semver = "0.5" url = "1.2" regex = "0.1" diff --git a/lib/domain/libimagbookmark/src/lib.rs b/lib/domain/libimagbookmark/src/lib.rs index e5a34357..0a864121 100644 --- a/lib/domain/libimagbookmark/src/lib.rs +++ b/lib/domain/libimagbookmark/src/lib.rs @@ -33,7 +33,6 @@ while_true, )] -extern crate semver; extern crate url; extern crate regex; diff --git a/lib/domain/libimagcounter/Cargo.toml b/lib/domain/libimagcounter/Cargo.toml index 01519e14..842c15d3 100644 --- a/lib/domain/libimagcounter/Cargo.toml +++ b/lib/domain/libimagcounter/Cargo.toml @@ -17,7 +17,6 @@ homepage = "http://imag-pim.org" log = "0.3" toml = "0.4.*" toml-query = "0.3.*" -semver = "0.5" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/domain/libimagcounter/src/lib.rs b/lib/domain/libimagcounter/src/lib.rs index 13bf7367..cbbd043c 100644 --- a/lib/domain/libimagcounter/src/lib.rs +++ b/lib/domain/libimagcounter/src/lib.rs @@ -36,7 +36,6 @@ extern crate toml; extern crate toml_query; #[macro_use] extern crate log; -extern crate semver; #[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagerror; diff --git a/lib/domain/libimagdiary/Cargo.toml b/lib/domain/libimagdiary/Cargo.toml index 1da26c75..fbcdbb37 100644 --- a/lib/domain/libimagdiary/Cargo.toml +++ b/lib/domain/libimagdiary/Cargo.toml @@ -16,15 +16,12 @@ homepage = "http://imag-pim.org" [dependencies] chrono = "0.4" log = "0.3" -semver = "0.5" toml = "0.4.*" toml-query = "0.3.*" -regex = "0.1" itertools = "0.5" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } -libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } libimagentryedit = { version = "0.4.0", path = "../../../lib/entry/libimagentryedit" } libimagentryview = { version = "0.4.0", path = "../../../lib/entry/libimagentryview" } diff --git a/lib/domain/libimagdiary/src/lib.rs b/lib/domain/libimagdiary/src/lib.rs index fcabc94e..ca54f902 100644 --- a/lib/domain/libimagdiary/src/lib.rs +++ b/lib/domain/libimagdiary/src/lib.rs @@ -35,10 +35,8 @@ extern crate chrono; #[macro_use] extern crate log; -extern crate semver; extern crate toml; extern crate toml_query; -extern crate regex; extern crate itertools; #[macro_use] extern crate libimagstore; @@ -46,7 +44,6 @@ extern crate itertools; extern crate libimagentryedit; extern crate libimagentryview; extern crate libimagrt; -extern crate libimagutil; module_entry_path_mod!("diary"); diff --git a/lib/domain/libimagmail/Cargo.toml b/lib/domain/libimagmail/Cargo.toml index f3ab1e88..69a434ea 100644 --- a/lib/domain/libimagmail/Cargo.toml +++ b/lib/domain/libimagmail/Cargo.toml @@ -16,8 +16,6 @@ homepage = "http://imag-pim.org" [dependencies] log = "0.3" email = "0.0.17" -semver = "0.5" -toml = "0.4.*" filters = "0.1.*" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/domain/libimagmail/src/lib.rs b/lib/domain/libimagmail/src/lib.rs index ae3fa850..14200eaf 100644 --- a/lib/domain/libimagmail/src/lib.rs +++ b/lib/domain/libimagmail/src/lib.rs @@ -35,8 +35,6 @@ #[macro_use] extern crate log; extern crate email; -extern crate semver; -extern crate toml; extern crate filters; #[macro_use] extern crate libimagerror; diff --git a/lib/domain/libimagnotes/Cargo.toml b/lib/domain/libimagnotes/Cargo.toml index 3b19375a..8b9159c2 100644 --- a/lib/domain/libimagnotes/Cargo.toml +++ b/lib/domain/libimagnotes/Cargo.toml @@ -14,7 +14,6 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -semver = "0.5" log = "0.3" toml = "^0.4" toml-query = "0.3.0" @@ -23,4 +22,3 @@ libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagentryedit = { version = "0.4.0", path = "../../../lib/entry/libimagentryedit" } -libimagentrytag = { version = "0.4.0", path = "../../../lib/entry/libimagentrytag" } diff --git a/lib/domain/libimagnotes/src/lib.rs b/lib/domain/libimagnotes/src/lib.rs index 3fa1f5d2..699701ac 100644 --- a/lib/domain/libimagnotes/src/lib.rs +++ b/lib/domain/libimagnotes/src/lib.rs @@ -34,7 +34,6 @@ )] #[macro_use] extern crate log; -extern crate semver; extern crate toml; extern crate toml_query; @@ -42,7 +41,6 @@ extern crate libimagrt; #[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagerror; extern crate libimagentryedit; -extern crate libimagentrytag; module_entry_path_mod!("notes"); diff --git a/lib/domain/libimagtodo/Cargo.toml b/lib/domain/libimagtodo/Cargo.toml index 65b4ee26..5d211f0c 100644 --- a/lib/domain/libimagtodo/Cargo.toml +++ b/lib/domain/libimagtodo/Cargo.toml @@ -14,15 +14,12 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -semver = "0.2" task-hookrs = "0.2.2" uuid = "0.3" toml = "0.4.*" toml-query = "0.3.*" -is-match = "0.1.*" log = "0.3" serde_json = "0.8" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } -libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } diff --git a/lib/domain/libimagtodo/src/lib.rs b/lib/domain/libimagtodo/src/lib.rs index c1289f8d..7961a7a1 100644 --- a/lib/domain/libimagtodo/src/lib.rs +++ b/lib/domain/libimagtodo/src/lib.rs @@ -33,17 +33,14 @@ while_true, )] -extern crate semver; extern crate uuid; extern crate toml; extern crate toml_query; -#[macro_use] extern crate is_match; #[macro_use] extern crate log; extern crate serde_json; #[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagerror; -extern crate libimagutil; extern crate task_hookrs; module_entry_path_mod!("todo"); diff --git a/lib/entry/libimagentryannotation/Cargo.toml b/lib/entry/libimagentryannotation/Cargo.toml index 33666606..9d1434de 100644 --- a/lib/entry/libimagentryannotation/Cargo.toml +++ b/lib/entry/libimagentryannotation/Cargo.toml @@ -10,7 +10,6 @@ readme = "../README.md" license = "LGPL-2.1" [dependencies] -uuid = { version = "0.3.1", features = ["v4"] } lazy_static = "0.1.15" toml = "^0.4" toml-query = "0.3.0" @@ -19,4 +18,3 @@ libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagnotes = { version = "0.4.0", path = "../../../lib/domain/libimagnotes" } libimagentrylink = { version = "0.4.0", path = "../../../lib/entry/libimagentrylink" } -libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } diff --git a/lib/entry/libimagentryannotation/src/lib.rs b/lib/entry/libimagentryannotation/src/lib.rs index 69a1fc1c..5b784de4 100644 --- a/lib/entry/libimagentryannotation/src/lib.rs +++ b/lib/entry/libimagentryannotation/src/lib.rs @@ -33,7 +33,6 @@ while_true, )] -extern crate uuid; extern crate toml; extern crate toml_query; @@ -41,7 +40,6 @@ extern crate toml_query; extern crate libimagstore; extern crate libimagentrylink; extern crate libimagnotes; -extern crate libimagutil; pub mod annotateable; pub mod annotation_fetcher; diff --git a/lib/entry/libimagentrydatetime/Cargo.toml b/lib/entry/libimagentrydatetime/Cargo.toml index a024c6d4..aae32c6a 100644 --- a/lib/entry/libimagentrydatetime/Cargo.toml +++ b/lib/entry/libimagentrydatetime/Cargo.toml @@ -21,5 +21,4 @@ toml = "0.4" libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } -libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } diff --git a/lib/entry/libimagentrydatetime/src/lib.rs b/lib/entry/libimagentrydatetime/src/lib.rs index 695ce974..06cf6f22 100644 --- a/lib/entry/libimagentrydatetime/src/lib.rs +++ b/lib/entry/libimagentrydatetime/src/lib.rs @@ -40,7 +40,6 @@ extern crate toml; #[macro_use] extern crate libimagerror; extern crate libimagstore; -extern crate libimagutil; pub mod datepath; pub mod datetime; diff --git a/lib/entry/libimagentryfilter/src/lib.rs b/lib/entry/libimagentryfilter/src/lib.rs index 1dc3c988..aa9bae13 100644 --- a/lib/entry/libimagentryfilter/src/lib.rs +++ b/lib/entry/libimagentryfilter/src/lib.rs @@ -34,7 +34,6 @@ )] extern crate filters; -extern crate itertools; extern crate regex; extern crate semver; extern crate toml; diff --git a/lib/entry/libimagentrylink/Cargo.toml b/lib/entry/libimagentrylink/Cargo.toml index a0118b18..01a8508c 100644 --- a/lib/entry/libimagentrylink/Cargo.toml +++ b/lib/entry/libimagentrylink/Cargo.toml @@ -17,7 +17,6 @@ homepage = "http://imag-pim.org" itertools = "0.5" log = "0.3" toml = "^0.4" -semver = "0.5" url = "1.2" rust-crypto = "0.2" env_logger = "0.3" diff --git a/lib/entry/libimagentrylink/src/lib.rs b/lib/entry/libimagentrylink/src/lib.rs index f706e923..4df88cc7 100644 --- a/lib/entry/libimagentrylink/src/lib.rs +++ b/lib/entry/libimagentrylink/src/lib.rs @@ -37,7 +37,6 @@ extern crate itertools; #[macro_use] extern crate log; extern crate toml; extern crate toml_query; -extern crate semver; extern crate url; extern crate crypto; #[macro_use] extern crate is_match; diff --git a/lib/entry/libimagentrylist/Cargo.toml b/lib/entry/libimagentrylist/Cargo.toml index c28354da..66ed5c4b 100644 --- a/lib/entry/libimagentrylist/Cargo.toml +++ b/lib/entry/libimagentrylist/Cargo.toml @@ -16,7 +16,6 @@ homepage = "http://imag-pim.org" [dependencies] clap = ">=2.17" log = "0.3" -toml = "^0.4" prettytable-rs = "0.6.*" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/entry/libimagentrylist/src/lib.rs b/lib/entry/libimagentrylist/src/lib.rs index ee97d72c..8fb0186e 100644 --- a/lib/entry/libimagentrylist/src/lib.rs +++ b/lib/entry/libimagentrylist/src/lib.rs @@ -35,7 +35,6 @@ extern crate clap; #[macro_use] extern crate log; -extern crate toml; extern crate prettytable; extern crate libimagstore; diff --git a/lib/entry/libimagentrymarkdown/Cargo.toml b/lib/entry/libimagentrymarkdown/Cargo.toml index 5951f36a..b710d4a0 100644 --- a/lib/entry/libimagentrymarkdown/Cargo.toml +++ b/lib/entry/libimagentrymarkdown/Cargo.toml @@ -16,7 +16,6 @@ homepage = "http://imag-pim.org" [dependencies] log = "0.3" hoedown = "5.0.0" -crossbeam = "0.2" url = "1.2" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/entry/libimagentrymarkdown/src/lib.rs b/lib/entry/libimagentrymarkdown/src/lib.rs index 2d0ad848..4cd31d0a 100644 --- a/lib/entry/libimagentrymarkdown/src/lib.rs +++ b/lib/entry/libimagentrymarkdown/src/lib.rs @@ -33,7 +33,6 @@ while_true, )] -extern crate crossbeam; extern crate hoedown; extern crate url; extern crate libimagstore; diff --git a/lib/entry/libimagentryref/Cargo.toml b/lib/entry/libimagentryref/Cargo.toml index a60b8c9c..7e2a918c 100644 --- a/lib/entry/libimagentryref/Cargo.toml +++ b/lib/entry/libimagentryref/Cargo.toml @@ -17,13 +17,10 @@ homepage = "http://imag-pim.org" itertools = "0.5" log = "0.3" rust-crypto = "0.2" -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" } libimagentrylist = { version = "0.4.0", path = "../../../lib/entry/libimagentrylist" } -libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } diff --git a/lib/entry/libimagentryref/src/lib.rs b/lib/entry/libimagentryref/src/lib.rs index 1bd54a40..17cbe112 100644 --- a/lib/entry/libimagentryref/src/lib.rs +++ b/lib/entry/libimagentryref/src/lib.rs @@ -36,15 +36,12 @@ #[macro_use] extern crate log; extern crate crypto; extern crate itertools; -extern crate semver; extern crate toml; extern crate toml_query; -extern crate version; extern crate walkdir; #[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagerror; -extern crate libimagutil; extern crate libimagentrylist; module_entry_path_mod!("ref"); diff --git a/lib/entry/libimagentrytag/Cargo.toml b/lib/entry/libimagentrytag/Cargo.toml index 1732fb64..2c15ff5d 100644 --- a/lib/entry/libimagentrytag/Cargo.toml +++ b/lib/entry/libimagentrytag/Cargo.toml @@ -25,4 +25,3 @@ toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } -libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } diff --git a/lib/entry/libimagentrytag/src/lib.rs b/lib/entry/libimagentrytag/src/lib.rs index cb86d7a6..4c1fdcb3 100644 --- a/lib/entry/libimagentrytag/src/lib.rs +++ b/lib/entry/libimagentrytag/src/lib.rs @@ -44,7 +44,6 @@ extern crate filters; extern crate libimagstore; #[macro_use] extern crate libimagerror; -extern crate libimagutil; pub mod error; pub mod exec; diff --git a/lib/entry/libimagentryview/Cargo.toml b/lib/entry/libimagentryview/Cargo.toml index 201215b6..c0fb166d 100644 --- a/lib/entry/libimagentryview/Cargo.toml +++ b/lib/entry/libimagentryview/Cargo.toml @@ -16,7 +16,6 @@ homepage = "http://imag-pim.org" [dependencies] log = "0.3" toml = "^0.4" -glob = "0.2" libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/entry/libimagentryview/src/lib.rs b/lib/entry/libimagentryview/src/lib.rs index 55d58d6a..1aefc2eb 100644 --- a/lib/entry/libimagentryview/src/lib.rs +++ b/lib/entry/libimagentryview/src/lib.rs @@ -33,7 +33,6 @@ while_true, )] -extern crate glob; extern crate toml; extern crate libimagstore; diff --git a/lib/etc/libimaginteraction/Cargo.toml b/lib/etc/libimaginteraction/Cargo.toml index 6ed38c94..0de941e6 100644 --- a/lib/etc/libimaginteraction/Cargo.toml +++ b/lib/etc/libimaginteraction/Cargo.toml @@ -21,10 +21,6 @@ lazy_static = "0.2.*" log = "0.3" regex = "0.2" toml = "^0.4" -spinner = "0.4" -rustyline = "1.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } -libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } -libimagentryfilter = { version = "0.4.0", path = "../../../lib/entry/libimagentryfilter" } diff --git a/lib/etc/libimaginteraction/src/lib.rs b/lib/etc/libimaginteraction/src/lib.rs index b0663f8b..cd38071a 100644 --- a/lib/etc/libimaginteraction/src/lib.rs +++ b/lib/etc/libimaginteraction/src/lib.rs @@ -33,18 +33,14 @@ while_true, )] -extern crate spinner; extern crate interactor; extern crate ansi_term; #[macro_use] extern crate lazy_static; extern crate regex; extern crate clap; extern crate toml; -extern crate rustyline; -extern crate libimagentryfilter; extern crate libimagstore; -extern crate libimagutil; #[macro_use] extern crate libimagerror; pub mod ask; From ac804bd839418c0cd89914f21e8bd207cc0acb08 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 29 Aug 2017 17:22:58 +0200 Subject: [PATCH 09/17] Remove unused keyword "mut" where not needed --- bin/core/imag-store/src/create.rs | 4 ++-- bin/core/imag-store/src/update.rs | 2 +- .../src/file_abstraction/inmemory.rs | 8 ++++---- .../src/file_abstraction/stdio/out.rs | 2 +- lib/core/libimagstore/src/store.rs | 4 ++-- lib/domain/libimagcounter/src/counter.rs | 16 +++++++++------- lib/domain/libimagnotes/src/note.rs | 9 +++++---- lib/domain/libimagtodo/src/task.rs | 2 +- lib/entry/libimagentrylink/src/external.rs | 2 +- 9 files changed, 26 insertions(+), 23 deletions(-) diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs index e015595f..f434ba75 100644 --- a/bin/core/imag-store/src/create.rs +++ b/bin/core/imag-store/src/create.rs @@ -147,12 +147,12 @@ fn create_with_content_and_header(rt: &Runtime, .map_dbg_err(|e| format!("Error in Store::create(): {:?}", e)) .map(|mut element| { { - let mut e_content = element.get_content_mut(); + let e_content = element.get_content_mut(); *e_content = content; debug!("New content set"); } { - let mut e_header = element.get_header_mut(); + let e_header = element.get_header_mut(); *e_header = header; debug!("New header set"); } diff --git a/bin/core/imag-store/src/update.rs b/bin/core/imag-store/src/update.rs index bdcfb6de..d0f245d5 100644 --- a/bin/core/imag-store/src/update.rs +++ b/bin/core/imag-store/src/update.rs @@ -41,7 +41,7 @@ pub fn update(rt: &Runtime) { rt.store() .retrieve(path) .map(|mut locked_e| { - let mut e = locked_e.deref_mut(); + let e = locked_e.deref_mut(); scmd.value_of("content") .map(|new_content| { diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs index 57ca2411..4f318fe1 100644 --- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs +++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs @@ -80,7 +80,7 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance { match *self { InMemoryFileAbstractionInstance { ref absent_path, .. } => { let mut mtx = self.fs_abstraction.lock().expect("Locking Mutex failed"); - let mut backend = mtx.get_mut(); + let backend = mtx.get_mut(); let _ = backend.insert(absent_path.clone(), buf.clone()); return Ok(()); }, @@ -130,7 +130,7 @@ impl FileAbstraction for InMemoryFileAbstraction { fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> { debug!("Copying : {:?} -> {:?}", from, to); let mut mtx = self.backend().lock().expect("Locking Mutex failed"); - let mut backend = mtx.get_mut(); + let backend = mtx.get_mut(); let a = try!(backend.get(from).cloned().ok_or(SEK::FileNotFound.into_error())); backend.insert(to.clone(), a); @@ -141,7 +141,7 @@ impl FileAbstraction for InMemoryFileAbstraction { fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> { debug!("Renaming: {:?} -> {:?}", from, to); let mut mtx = self.backend().lock().expect("Locking Mutex failed"); - let mut backend = mtx.get_mut(); + let backend = mtx.get_mut(); let a = try!(backend.get(from).cloned().ok_or(SEK::FileNotFound.into_error())); backend.insert(to.clone(), a); @@ -164,7 +164,7 @@ impl FileAbstraction for InMemoryFileAbstraction { fn fill<'a>(&'a mut self, mut d: Drain) -> Result<(), SE> { debug!("Draining into : {:?}", self); let mut mtx = try!(self.backend().lock().map_err(|_| SEK::LockError.into_error())); - let mut backend = mtx.get_mut(); + let backend = mtx.get_mut(); for (path, element) in d.iter() { debug!("Drain into {:?}: {:?}", self, path); diff --git a/lib/core/libimagstore/src/file_abstraction/stdio/out.rs b/lib/core/libimagstore/src/file_abstraction/stdio/out.rs index eca99114..37ccab62 100644 --- a/lib/core/libimagstore/src/file_abstraction/stdio/out.rs +++ b/lib/core/libimagstore/src/file_abstraction/stdio/out.rs @@ -143,7 +143,7 @@ impl FileAbstraction for StdoutFileAbstraction { fn fill(&mut self, mut d: Drain) -> Result<(), SE> { debug!("Draining into : {:?}", self); let mut mtx = try!(self.backend().lock().map_err(|_| SEK::IoError.into_error())); - let mut backend = mtx.get_mut(); + let backend = mtx.get_mut(); for (path, element) in d.iter() { debug!("Drain into {:?}: {:?}", self, path); diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index af7e5aaf..ba66641a 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -452,7 +452,7 @@ impl Store { .map_err(|_| SE::new(SEK::LockPoisoned, None)) .and_then(|mut es| { let new_se = try!(StoreEntry::new(id.clone(), &self.backend)); - let mut se = es.entry(id.clone()).or_insert(new_se); + let se = es.entry(id.clone()).or_insert(new_se); let entry = se.get_entry(); se.status = StoreEntryStatus::Borrowed; entry @@ -564,7 +564,7 @@ impl Store { Ok(e) => e, }; - let mut se = try!(hsmap.get_mut(&entry.location).ok_or(SE::new(SEK::IdNotFound, None))); + let se = try!(hsmap.get_mut(&entry.location).ok_or(SE::new(SEK::IdNotFound, None))); assert!(se.is_borrowed(), "Tried to update a non borrowed entry."); diff --git a/lib/domain/libimagcounter/src/counter.rs b/lib/domain/libimagcounter/src/counter.rs index 7b6c1d3c..b34219a0 100644 --- a/lib/domain/libimagcounter/src/counter.rs +++ b/lib/domain/libimagcounter/src/counter.rs @@ -75,8 +75,8 @@ impl<'a> Counter<'a> { let mut lockentry = try!(store.create(id).map_err_into(CEK::StoreWriteError)); { - let mut entry = lockentry.deref_mut(); - let mut header = entry.get_header_mut(); + let entry = lockentry.deref_mut(); + let header = entry.get_header_mut(); let setres = header.set(&String::from("counter"), Value::Table(BTreeMap::new())); if setres.is_err() { return Err(CEK::StoreWriteError.into_error()); @@ -103,7 +103,7 @@ impl<'a> Counter<'a> { self.unit = unit; if let Some(u) = self.unit.clone() { - let mut header = self.fle.deref_mut().get_header_mut(); + let header = self.fle.deref_mut().get_header_mut(); let setres = header.set(&String::from("counter.unit"), Value::String(u.0)); if setres.is_err() { self.unit = None; @@ -114,7 +114,7 @@ impl<'a> Counter<'a> { } pub fn inc(&mut self) -> Result<()> { - let mut header = self.fle.deref_mut().get_header_mut(); + let header = self.fle.deref_mut().get_header_mut(); let query = String::from("counter.value"); match try!(header.read(&query).map_err_into(CEK::StoreReadError)) { Some(&Value::Integer(i)) => { @@ -127,7 +127,7 @@ impl<'a> Counter<'a> { } pub fn dec(&mut self) -> Result<()> { - let mut header = self.fle.deref_mut().get_header_mut(); + let header = self.fle.deref_mut().get_header_mut(); let query = String::from("counter.value"); match try!(header.read(&query).map_err_into(CEK::StoreReadError)) { Some(&Value::Integer(i)) => { @@ -144,8 +144,10 @@ impl<'a> Counter<'a> { } pub fn set(&mut self, v: i64) -> Result<()> { - let mut header = self.fle.deref_mut().get_header_mut(); - header.set(&String::from("counter.value"), Value::Integer(v)) + self.fle + .deref_mut() + .get_header_mut() + .set(&String::from("counter.value"), Value::Integer(v)) .map_err_into(CEK::StoreWriteError) .map(|_| ()) } diff --git a/lib/domain/libimagnotes/src/note.rs b/lib/domain/libimagnotes/src/note.rs index 74991146..feaa8818 100644 --- a/lib/domain/libimagnotes/src/note.rs +++ b/lib/domain/libimagnotes/src/note.rs @@ -58,10 +58,10 @@ impl<'a> Note<'a> { .map_err_into(NEK::StoreWriteError)); { - let mut entry = lockentry.deref_mut(); + let entry = lockentry.deref_mut(); { - let mut header = entry.get_header_mut(); + let header = entry.get_header_mut(); let setres = header.set("note", Value::Table(BTreeMap::new())); if setres.is_err() { let kind = NEK::StoreWriteError; @@ -85,8 +85,9 @@ impl<'a> Note<'a> { } pub fn set_name(&mut self, n: String) -> Result<()> { - let mut header = self.entry.get_header_mut(); - header.set("note.name", Value::String(n)) + self.entry + .get_header_mut() + .set("note.name", Value::String(n)) .map_err(|e| NE::new(NEK::StoreWriteError, Some(Box::new(e)))) .map(|_| ()) } diff --git a/lib/domain/libimagtodo/src/task.rs b/lib/domain/libimagtodo/src/task.rs index 303ef14b..32faa337 100644 --- a/lib/domain/libimagtodo/src/task.rs +++ b/lib/domain/libimagtodo/src/task.rs @@ -236,7 +236,7 @@ impl<'a> IntoTask<'a> for TTask { .map_err_into(TEK::StoreError) .and_then(|mut fle| { { - let mut hdr = fle.get_header_mut(); + let hdr = fle.get_header_mut(); if try!(hdr.read("todo").map_err_into(TEK::StoreError)).is_none() { try!(hdr .set("todo", Value::Table(BTreeMap::new())) diff --git a/lib/entry/libimagentrylink/src/external.rs b/lib/entry/libimagentrylink/src/external.rs index 8ebd060d..75fb6451 100644 --- a/lib/entry/libimagentrylink/src/external.rs +++ b/lib/entry/libimagentrylink/src/external.rs @@ -350,7 +350,7 @@ impl ExternalLinker for Entry { debug!("Generating header content!"); { - let mut hdr = file.deref_mut().get_header_mut(); + let hdr = file.deref_mut().get_header_mut(); let mut table = match hdr.read("imag.content") { Ok(Some(&Value::Table(ref table))) => table.clone(), From 991fd7c3d464f9084ca43ad1972d2c82c672db3e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 30 Aug 2017 23:12:34 +0200 Subject: [PATCH 10/17] Remove unused variable --- lib/domain/libimagtodo/src/task.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/domain/libimagtodo/src/task.rs b/lib/domain/libimagtodo/src/task.rs index 32faa337..3dbbd04c 100644 --- a/lib/domain/libimagtodo/src/task.rs +++ b/lib/domain/libimagtodo/src/task.rs @@ -220,13 +220,6 @@ impl<'a> IntoTask<'a> for TTask { use toml_query::read::TomlValueReadExt; use toml_query::set::TomlValueSetExt; - // Helper for toml_query::read::TomlValueReadExt::read() return value, which does only - // return Result instead of Result>, which is a real inconvenience. - // - let no_identifier = |e: &::toml_query::error::Error| -> bool { - is_match!(e.kind(), &::toml_query::error::ErrorKind::IdentifierNotFoundInDocument(_)) - }; - let uuid = self.uuid(); ModuleEntryPath::new(format!("taskwarrior/{}", uuid)) .into_storeid() From fabb9903363db4b8e8ae87e12d253384e70fb5e0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 30 Aug 2017 23:19:24 +0200 Subject: [PATCH 11/17] Remove unused imports --- bin/domain/imag-mail/src/main.rs | 1 - bin/domain/imag-mail/src/ui.rs | 2 +- bin/domain/imag-timetrack/src/cont.rs | 3 --- bin/domain/imag-timetrack/src/day.rs | 5 ----- bin/domain/imag-timetrack/src/list.rs | 7 ------- bin/domain/imag-timetrack/src/month.rs | 6 ------ bin/domain/imag-timetrack/src/stop.rs | 1 - bin/domain/imag-timetrack/src/week.rs | 5 ----- bin/domain/imag-timetrack/src/year.rs | 6 ------ 9 files changed, 1 insertion(+), 35 deletions(-) diff --git a/bin/domain/imag-mail/src/main.rs b/bin/domain/imag-mail/src/main.rs index cb910630..4b4423e2 100644 --- a/bin/domain/imag-mail/src/main.rs +++ b/bin/domain/imag-mail/src/main.rs @@ -32,7 +32,6 @@ use libimagmail::mail::Mail; use libimagentryref::reference::Ref; use libimagrt::runtime::Runtime; use libimagrt::setup::generate_runtime_setup; -use libimagutil::debug_result::*; use libimagutil::info_result::*; mod ui; diff --git a/bin/domain/imag-mail/src/ui.rs b/bin/domain/imag-mail/src/ui.rs index c997d969..332522df 100644 --- a/bin/domain/imag-mail/src/ui.rs +++ b/bin/domain/imag-mail/src/ui.rs @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use clap::{Arg, ArgGroup, App, SubCommand}; +use clap::{Arg, App, SubCommand}; pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { app diff --git a/bin/domain/imag-timetrack/src/cont.rs b/bin/domain/imag-timetrack/src/cont.rs index 58075ad4..ae043562 100644 --- a/bin/domain/imag-timetrack/src/cont.rs +++ b/bin/domain/imag-timetrack/src/cont.rs @@ -18,12 +18,9 @@ // use std::cmp::Ord; -use std::cmp::Ordering; -use filters::ops::not::Not; use filters::filter::Filter; use itertools::Itertools; -use itertools::MinMaxResult; use chrono::NaiveDateTime; use libimagerror::trace::trace_error; diff --git a/bin/domain/imag-timetrack/src/day.rs b/bin/domain/imag-timetrack/src/day.rs index 1557a05a..bd76867d 100644 --- a/bin/domain/imag-timetrack/src/day.rs +++ b/bin/domain/imag-timetrack/src/day.rs @@ -17,14 +17,9 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::cmp::Ord; -use std::cmp::Ordering; use std::str::FromStr; -use filters::ops::not::Not; use filters::filter::Filter; -use itertools::Itertools; -use itertools::MinMaxResult; use chrono::NaiveDateTime; use libimagerror::trace::trace_error; diff --git a/bin/domain/imag-timetrack/src/list.rs b/bin/domain/imag-timetrack/src/list.rs index 6de2f5b8..b7fee298 100644 --- a/bin/domain/imag-timetrack/src/list.rs +++ b/bin/domain/imag-timetrack/src/list.rs @@ -17,15 +17,9 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::cmp::Ord; -use std::cmp::Ordering; use std::str::FromStr; -use filters::ops::not::Not; use filters::filter::Filter; -use itertools::Itertools; -use itertools::MinMaxResult; -use chrono::NaiveDateTime; use libimagerror::trace::trace_error; use libimagerror::trace::MapErrTrace; @@ -33,7 +27,6 @@ use libimagerror::iter::TraceIterator; use libimagstore::store::FileLockEntry; use libimagtimetrack::timetrackingstore::TimeTrackStore; use libimagtimetrack::timetracking::TimeTracking; -use libimagtimetrack::iter::filter::*; use libimagrt::runtime::Runtime; diff --git a/bin/domain/imag-timetrack/src/month.rs b/bin/domain/imag-timetrack/src/month.rs index b29ba27e..80ddd8f2 100644 --- a/bin/domain/imag-timetrack/src/month.rs +++ b/bin/domain/imag-timetrack/src/month.rs @@ -17,14 +17,9 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::cmp::Ord; -use std::cmp::Ordering; use std::str::FromStr; -use filters::ops::not::Not; use filters::filter::Filter; -use itertools::Itertools; -use itertools::MinMaxResult; use chrono::NaiveDateTime; use libimagerror::trace::trace_error; @@ -44,7 +39,6 @@ pub fn month(rt: &Runtime) -> i32 { let filter = { use chrono::offset::Local; use chrono::naive::NaiveDate; - use chrono::Weekday; use chrono::Datelike; let now = Local::now(); diff --git a/bin/domain/imag-timetrack/src/stop.rs b/bin/domain/imag-timetrack/src/stop.rs index 86e68004..64979096 100644 --- a/bin/domain/imag-timetrack/src/stop.rs +++ b/bin/domain/imag-timetrack/src/stop.rs @@ -24,7 +24,6 @@ use filters::filter::Filter; use libimagerror::trace::trace_error; use libimagerror::iter::TraceIterator; use libimagrt::runtime::Runtime; -use libimagrt::setup::generate_runtime_setup; use libimagtimetrack::timetracking::TimeTracking; use libimagtimetrack::tag::TimeTrackingTag; diff --git a/bin/domain/imag-timetrack/src/week.rs b/bin/domain/imag-timetrack/src/week.rs index 51a788ec..39acdf13 100644 --- a/bin/domain/imag-timetrack/src/week.rs +++ b/bin/domain/imag-timetrack/src/week.rs @@ -17,14 +17,9 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::cmp::Ord; -use std::cmp::Ordering; use std::str::FromStr; -use filters::ops::not::Not; use filters::filter::Filter; -use itertools::Itertools; -use itertools::MinMaxResult; use chrono::NaiveDateTime; use libimagerror::trace::trace_error; diff --git a/bin/domain/imag-timetrack/src/year.rs b/bin/domain/imag-timetrack/src/year.rs index b0e003b8..11b01974 100644 --- a/bin/domain/imag-timetrack/src/year.rs +++ b/bin/domain/imag-timetrack/src/year.rs @@ -17,14 +17,9 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::cmp::Ord; -use std::cmp::Ordering; use std::str::FromStr; -use filters::ops::not::Not; use filters::filter::Filter; -use itertools::Itertools; -use itertools::MinMaxResult; use chrono::NaiveDateTime; use libimagerror::trace::trace_error; @@ -44,7 +39,6 @@ pub fn year(rt: &Runtime) -> i32 { let filter = { use chrono::offset::Local; use chrono::naive::NaiveDate; - use chrono::Weekday; use chrono::Datelike; let now = Local::now(); From 00b8d5192cb2dd2d672df4b80d8c0c2ecf0ab8ad Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 30 Aug 2017 23:19:40 +0200 Subject: [PATCH 12/17] Remove unused variables --- bin/domain/imag-mail/src/main.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bin/domain/imag-mail/src/main.rs b/bin/domain/imag-mail/src/main.rs index 4b4423e2..5fd6d1d4 100644 --- a/bin/domain/imag-mail/src/main.rs +++ b/bin/domain/imag-mail/src/main.rs @@ -61,7 +61,7 @@ fn import_mail(rt: &Runtime) { let scmd = rt.cli().subcommand_matches("import-mail").unwrap(); let path = scmd.value_of("path").unwrap(); // enforced by clap - Mail::import_from_path(rt.store(), path) + let _ = Mail::import_from_path(rt.store(), path) .map_err_trace() .map_info_str("Ok"); } @@ -70,11 +70,6 @@ fn list(rt: &Runtime) { use libimagmail::error::MailErrorKind as MEK; use libimagmail::error::MapErrInto; - let scmd = rt.cli().subcommand_matches("list").unwrap(); - let do_check_dead = scmd.is_present("check-dead"); - let do_check_changed = scmd.is_present("check-changed"); - let do_check_changed_content = scmd.is_present("check-changed-content"); - let do_check_changed_permiss = scmd.is_present("check-changed-permissions"); let store = rt.store(); let iter = match store.retrieve_for_module("ref") { @@ -140,7 +135,7 @@ fn list(rt: &Runtime) { } fn mail_store(rt: &Runtime) { - let scmd = rt.cli().subcommand_matches("mail-store").unwrap(); + let _ = rt.cli().subcommand_matches("mail-store").unwrap(); error!("This feature is currently not implemented."); unimplemented!() } From bc74ea7e41f4efaea6363525248bdf5c89e36670 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 30 Aug 2017 23:19:47 +0200 Subject: [PATCH 13/17] Fix copy-paste bug --- bin/domain/imag-timetrack/src/list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/domain/imag-timetrack/src/list.rs b/bin/domain/imag-timetrack/src/list.rs index b7fee298..25c0ce0c 100644 --- a/bin/domain/imag-timetrack/src/list.rs +++ b/bin/domain/imag-timetrack/src/list.rs @@ -69,7 +69,7 @@ pub fn list(rt: &Runtime) -> i32 { }; let end_time_filter = |timetracking: &FileLockEntry| { - start.map(|s| match timetracking.get_end_datetime() { + end.map(|s| match timetracking.get_end_datetime() { Ok(Some(dt)) => dt <= s, Ok(None) => list_not_ended, Err(e) => { From 0732962b59479c917f50a155cc0b3f570ffa5e3b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 30 Aug 2017 23:20:10 +0200 Subject: [PATCH 14/17] Fix unused macro_use import --- bin/core/imag-tag/src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/core/imag-tag/src/main.rs b/bin/core/imag-tag/src/main.rs index 882a4053..1829b3fd 100644 --- a/bin/core/imag-tag/src/main.rs +++ b/bin/core/imag-tag/src/main.rs @@ -28,9 +28,13 @@ extern crate libimagrt; extern crate libimagentrytag; extern crate libimagerror; +#[cfg(test)] #[macro_use] extern crate libimagutil; +#[cfg(not(test))] +extern crate libimagutil; + #[cfg(test)] extern crate toml_query; From 1c079c950107bc4c4c079eba59f58f037323e9e7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 30 Aug 2017 23:40:31 +0200 Subject: [PATCH 15/17] Import libimagutil properly --- bin/core/imag-link/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs index 6e3a92b8..f752558d 100644 --- a/bin/core/imag-link/src/main.rs +++ b/bin/core/imag-link/src/main.rs @@ -44,10 +44,13 @@ extern crate libimagrt; extern crate libimagstore; extern crate libimagerror; -#[allow(unused_imports)] +#[cfg(test)] #[macro_use] extern crate libimagutil; +#[cfg(not(test))] +extern crate libimagutil; + use std::ops::Deref; use libimagrt::runtime::Runtime; From a710a5b72b2fe8c759c99eabcf2bafd3fbc44795 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 31 Aug 2017 00:06:55 +0200 Subject: [PATCH 16/17] Remove unused variable --- lib/core/libimagerror/src/error_gen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/libimagerror/src/error_gen.rs b/lib/core/libimagerror/src/error_gen.rs index ccfd1575..eb06692c 100644 --- a/lib/core/libimagerror/src/error_gen.rs +++ b/lib/core/libimagerror/src/error_gen.rs @@ -252,7 +252,7 @@ mod test { } impl Display for CustomData { - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { + fn fmt(&self, _: &mut Formatter) -> Result<(), FmtError> { Ok(()) } } From 9094c22abfe9158d378d82a564493f08f5d71810 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 31 Aug 2017 00:11:52 +0200 Subject: [PATCH 17/17] Fix test helper function --- bin/core/imag-link/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs index f752558d..0acbf710 100644 --- a/bin/core/imag-link/src/main.rs +++ b/bin/core/imag-link/src/main.rs @@ -376,7 +376,11 @@ mod tests { } fn get_entry_links<'a>(entry: &'a FileLockEntry<'a>) -> TomlQueryResult<&'a Value> { - entry.get_header().read(&"imag.links".to_owned()) + match entry.get_header().read(&"imag.links".to_owned()) { + Err(e) => Err(e), + Ok(Some(v)) => Ok(v), + Ok(None) => panic!("Didn't find 'imag.links' in {:?}", entry), + } } fn links_toml_value<'a, I: IntoIterator>(links: I) -> Value {