Merge pull request #1034 from matthiasbeyer/integrate-remove-unused

Integrate remove unused
This commit is contained in:
Matthias Beyer 2017-08-31 21:38:02 +02:00 committed by GitHub
commit 22de22e6e5
106 changed files with 398 additions and 1204 deletions

View file

@ -14,13 +14,12 @@ repository = "https://github.com/matthiasbeyer/imag"
homepage = "http://imag-pim.org" homepage = "http://imag-pim.org"
[dependencies] [dependencies]
semver = "0.5.1"
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
version = "2.0.1" version = "2.0.1"
toml = "^0.4"
toml-query = "0.1"
url = "1.2" url = "1.2"
toml = "0.4"
toml-query = "0.3.0"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" }

View file

@ -34,21 +34,23 @@
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate clap; extern crate clap;
extern crate semver;
extern crate toml;
extern crate toml_query;
extern crate url; extern crate url;
#[macro_use] extern crate version; #[macro_use] extern crate version;
#[cfg(test)] extern crate toml;
#[cfg(test)] extern crate toml_query;
extern crate libimagentrylink; extern crate libimagentrylink;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagerror; extern crate libimagerror;
#[allow(unused_imports)] #[cfg(test)]
#[macro_use] #[macro_use]
extern crate libimagutil; extern crate libimagutil;
#[cfg(not(test))]
extern crate libimagutil;
use std::ops::Deref; use std::ops::Deref;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
@ -374,7 +376,11 @@ mod tests {
} }
fn get_entry_links<'a>(entry: &'a FileLockEntry<'a>) -> TomlQueryResult<&'a Value> { 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<Item = &'static str>>(links: I) -> Value { fn links_toml_value<'a, I: IntoIterator<Item = &'static str>>(links: I) -> Value {

View file

@ -14,12 +14,10 @@ repository = "https://github.com/matthiasbeyer/imag"
homepage = "http://imag-pim.org" homepage = "http://imag-pim.org"
[dependencies] [dependencies]
semver = "0.5.1"
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
version = "2.0.1" version = "2.0.1"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagentryref = { version = "0.4.0", path = "../../../lib/entry/libimagentryref" } libimagentryref = { version = "0.4.0", path = "../../../lib/entry/libimagentryref" }

View file

@ -34,10 +34,8 @@
#[macro_use] extern crate log; #[macro_use] extern crate log;
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate semver;
extern crate clap; extern crate clap;
extern crate libimagstore;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagentryref; extern crate libimagentryref;
extern crate libimagerror; extern crate libimagerror;

View file

@ -17,7 +17,6 @@ homepage = "http://imag-pim.org"
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
version = "2.0.1" version = "2.0.1"
semver = "0.5"
toml = "^0.4" toml = "^0.4"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore", features = ["verify"] } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore", features = ["verify"] }

View file

@ -147,12 +147,12 @@ fn create_with_content_and_header(rt: &Runtime,
.map_dbg_err(|e| format!("Error in Store::create(): {:?}", e)) .map_dbg_err(|e| format!("Error in Store::create(): {:?}", e))
.map(|mut element| { .map(|mut element| {
{ {
let mut e_content = element.get_content_mut(); let e_content = element.get_content_mut();
*e_content = content; *e_content = content;
debug!("New content set"); debug!("New content set");
} }
{ {
let mut e_header = element.get_header_mut(); let e_header = element.get_header_mut();
*e_header = header; *e_header = header;
debug!("New header set"); debug!("New header set");
} }

View file

@ -34,7 +34,6 @@
extern crate clap; extern crate clap;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate semver;
extern crate toml; extern crate toml;
#[macro_use] extern crate version; #[macro_use] extern crate version;

View file

@ -41,7 +41,7 @@ pub fn update(rt: &Runtime) {
rt.store() rt.store()
.retrieve(path) .retrieve(path)
.map(|mut locked_e| { .map(|mut locked_e| {
let mut e = locked_e.deref_mut(); let e = locked_e.deref_mut();
scmd.value_of("content") scmd.value_of("content")
.map(|new_content| { .map(|new_content| {

View file

@ -17,8 +17,7 @@ homepage = "http://imag-pim.org"
clap = "2.*" clap = "2.*"
log = "0.3" log = "0.3"
version = "2.0.1" version = "2.0.1"
semver = "0.2" toml = "0.4"
toml = "^0.4"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" }

View file

@ -19,18 +19,22 @@
extern crate clap; extern crate clap;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate semver;
extern crate toml;
#[macro_use] extern crate version; #[macro_use] extern crate version;
#[cfg(test)] extern crate toml;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagentrytag; extern crate libimagentrytag;
extern crate libimagerror; extern crate libimagerror;
#[cfg(test)]
#[macro_use] #[macro_use]
extern crate libimagutil; extern crate libimagutil;
#[cfg(not(test))]
extern crate libimagutil;
#[cfg(test)] #[cfg(test)]
extern crate toml_query; extern crate toml_query;

View file

@ -16,8 +16,6 @@ homepage = "http://imag-pim.org"
[dependencies] [dependencies]
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
semver = "0.5"
toml = "^0.4"
version = "2.0.1" version = "2.0.1"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }

View file

@ -34,8 +34,6 @@
extern crate clap; extern crate clap;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate semver;
extern crate toml;
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate libimagentryview; extern crate libimagentryview;

View file

@ -21,6 +21,5 @@ version = "2.0.1"
libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagbookmark = { version = "0.4.0", path = "../../../lib/domain/libimagbookmark" } 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" } libimagentrytag = { version = "0.4.0", path = "../../../lib/entry/libimagentrytag" }
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }

View file

@ -37,7 +37,6 @@ extern crate clap;
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate libimagbookmark; extern crate libimagbookmark;
extern crate libimagentrylink;
extern crate libimagentrytag; extern crate libimagentrytag;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagerror; extern crate libimagerror;

View file

@ -10,15 +10,11 @@ readme = "../README.md"
license = "LGPL-2.1" license = "LGPL-2.1"
[dependencies] [dependencies]
semver = "0.5"
clap = "2.*" clap = "2.*"
log = "0.3" log = "0.3"
version = "2.0.1" version = "2.0.1"
toml = "0.4.*"
url = "1.2"
libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagmail = { version = "0.4.0", path = "../../../lib/domain/libimagmail" } libimagmail = { version = "0.4.0", path = "../../../lib/domain/libimagmail" }
libimagentryref = { version = "0.4.0", path = "../../../lib/entry/libimagentryref" }
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }

View file

@ -17,10 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// //
extern crate semver;
extern crate clap; extern crate clap;
extern crate toml;
extern crate url;
#[macro_use] extern crate log; #[macro_use] extern crate log;
#[macro_use] extern crate version; #[macro_use] extern crate version;
@ -28,15 +25,11 @@ extern crate libimagrt;
extern crate libimagmail; extern crate libimagmail;
extern crate libimagerror; extern crate libimagerror;
extern crate libimagutil; extern crate libimagutil;
extern crate libimagentryref;
use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit}; use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit};
use libimagmail::mail::Mail; use libimagmail::mail::Mail;
use libimagentryref::reference::Ref;
use libimagentryref::refstore::RefStore;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagutil::debug_result::*;
use libimagutil::info_result::*; use libimagutil::info_result::*;
mod ui; mod ui;
@ -66,7 +59,7 @@ fn import_mail(rt: &Runtime) {
let scmd = rt.cli().subcommand_matches("import-mail").unwrap(); let scmd = rt.cli().subcommand_matches("import-mail").unwrap();
let path = scmd.value_of("path").unwrap(); // enforced by clap 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_err_trace()
.map_info_str("Ok"); .map_info_str("Ok");
} }
@ -75,11 +68,6 @@ fn list(rt: &Runtime) {
use libimagmail::error::MailErrorKind as MEK; use libimagmail::error::MailErrorKind as MEK;
use libimagmail::error::MapErrInto; 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 store = rt.store();
let iter = match store.retrieve_for_module("ref") { let iter = match store.retrieve_for_module("ref") {
@ -145,7 +133,7 @@ fn list(rt: &Runtime) {
} }
fn mail_store(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."); error!("This feature is currently not implemented.");
unimplemented!() unimplemented!()
} }

View file

@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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> { pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
app app

View file

@ -14,7 +14,6 @@ repository = "https://github.com/matthiasbeyer/imag"
homepage = "http://imag-pim.org" homepage = "http://imag-pim.org"
[dependencies] [dependencies]
semver = "0.2.1"
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
version = "2.0.1" version = "2.0.1"

View file

@ -19,7 +19,6 @@
extern crate clap; extern crate clap;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate semver;
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate itertools; extern crate itertools;

View file

@ -17,8 +17,6 @@ homepage = "http://imag-pim.org"
clap = "2.*" clap = "2.*"
log = "0.3" log = "0.3"
version = "2.0.1" version = "2.0.1"
semver = "0.2"
toml = "^0.4"
chrono = "^0.4" chrono = "^0.4"
filters = "0.1.1" filters = "0.1.1"
itertools = "0.6" 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" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagtimetrack = { version = "0.4.0", path = "../../../lib/domain/libimagtimetrack" } libimagtimetrack = { version = "0.4.0", path = "../../../lib/domain/libimagtimetrack" }
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }

View file

@ -18,12 +18,9 @@
// //
use std::cmp::Ord; use std::cmp::Ord;
use std::cmp::Ordering;
use filters::ops::not::Not;
use filters::filter::Filter; use filters::filter::Filter;
use itertools::Itertools; use itertools::Itertools;
use itertools::MinMaxResult;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;

View file

@ -17,14 +17,9 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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 std::str::FromStr;
use filters::ops::not::Not;
use filters::filter::Filter; use filters::filter::Filter;
use itertools::Itertools;
use itertools::MinMaxResult;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;

View file

@ -17,15 +17,9 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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 std::str::FromStr;
use filters::ops::not::Not;
use filters::filter::Filter; use filters::filter::Filter;
use itertools::Itertools;
use itertools::MinMaxResult;
use chrono::NaiveDateTime;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
@ -33,7 +27,6 @@ use libimagerror::iter::TraceIterator;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagtimetrack::timetrackingstore::TimeTrackStore; use libimagtimetrack::timetrackingstore::TimeTrackStore;
use libimagtimetrack::timetracking::TimeTracking; use libimagtimetrack::timetracking::TimeTracking;
use libimagtimetrack::iter::filter::*;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
@ -76,7 +69,7 @@ pub fn list(rt: &Runtime) -> i32 {
}; };
let end_time_filter = |timetracking: &FileLockEntry| { 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(Some(dt)) => dt <= s,
Ok(None) => list_not_ended, Ok(None) => list_not_ended,
Err(e) => { Err(e) => {

View file

@ -24,8 +24,6 @@ extern crate log;
extern crate version; extern crate version;
extern crate clap; extern crate clap;
extern crate semver;
extern crate toml;
extern crate chrono; extern crate chrono;
extern crate filters; extern crate filters;
extern crate itertools; extern crate itertools;
@ -34,7 +32,6 @@ extern crate libimagerror;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagtimetrack; extern crate libimagtimetrack;
extern crate libimagutil;
mod cont; mod cont;
mod day; mod day;

View file

@ -17,14 +17,9 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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 std::str::FromStr;
use filters::ops::not::Not;
use filters::filter::Filter; use filters::filter::Filter;
use itertools::Itertools;
use itertools::MinMaxResult;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
@ -44,7 +39,6 @@ pub fn month(rt: &Runtime) -> i32 {
let filter = { let filter = {
use chrono::offset::Local; use chrono::offset::Local;
use chrono::naive::NaiveDate; use chrono::naive::NaiveDate;
use chrono::Weekday;
use chrono::Datelike; use chrono::Datelike;
let now = Local::now(); let now = Local::now();

View file

@ -24,7 +24,6 @@ use filters::filter::Filter;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
use libimagerror::iter::TraceIterator; use libimagerror::iter::TraceIterator;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup;
use libimagtimetrack::timetracking::TimeTracking; use libimagtimetrack::timetracking::TimeTracking;
use libimagtimetrack::tag::TimeTrackingTag; use libimagtimetrack::tag::TimeTrackingTag;

View file

@ -17,14 +17,9 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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 std::str::FromStr;
use filters::ops::not::Not;
use filters::filter::Filter; use filters::filter::Filter;
use itertools::Itertools;
use itertools::MinMaxResult;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;

View file

@ -17,14 +17,9 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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 std::str::FromStr;
use filters::ops::not::Not;
use filters::filter::Filter; use filters::filter::Filter;
use itertools::Itertools;
use itertools::MinMaxResult;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
@ -44,7 +39,6 @@ pub fn year(rt: &Runtime) -> i32 {
let filter = { let filter = {
use chrono::offset::Local; use chrono::offset::Local;
use chrono::naive::NaiveDate; use chrono::naive::NaiveDate;
use chrono::Weekday;
use chrono::Datelike; use chrono::Datelike;
let now = Local::now(); let now = Local::now();

View file

@ -15,17 +15,12 @@ homepage = "http://imag-pim.org"
[dependencies] [dependencies]
clap = ">=2.17" clap = ">=2.17"
glob = "0.2.11"
log = "0.3.6" log = "0.3.6"
semver = "0.5.1"
serde_json = "0.8.3"
task-hookrs = "0.2.2"
toml = "0.4.*" toml = "0.4.*"
toml-query = "0.3.*" toml-query = "0.3.*"
is-match = "0.1.*" is-match = "0.1.*"
version = "2.0.1" version = "2.0.1"
libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } 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" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagtodo = { version = "0.4.0", path = "../../../lib/domain/libimagtodo" } libimagtodo = { version = "0.4.0", path = "../../../lib/domain/libimagtodo" }

View file

@ -18,19 +18,13 @@
// //
extern crate clap; extern crate clap;
extern crate glob;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate serde_json;
extern crate semver;
extern crate toml; extern crate toml;
extern crate toml_query; extern crate toml_query;
#[macro_use] extern crate is_match; #[macro_use] extern crate is_match;
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate task_hookrs;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagstore;
extern crate libimagerror; extern crate libimagerror;
extern crate libimagtodo; extern crate libimagtodo;

View file

@ -252,7 +252,7 @@ mod test {
} }
impl Display for CustomData { impl Display for CustomData {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { fn fmt(&self, _: &mut Formatter) -> Result<(), FmtError> {
Ok(()) Ok(())
} }
} }

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -26,6 +27,7 @@
unused_allocation, unused_allocation,
unused_import_braces, unused_import_braces,
unused_imports, unused_imports,
unused_must_use,
unused_mut, unused_mut,
unused_qualifications, unused_qualifications,
while_true, while_true,

View file

@ -20,9 +20,9 @@ toml = "^0.4"
log = "0.3" log = "0.3"
xdg-basedir = "1.0" xdg-basedir = "1.0"
itertools = "0.5" itertools = "0.5"
tempfile = "2.1"
ansi_term = "0.9" ansi_term = "0.9"
is-match = "0.1" is-match = "0.1"
toml-query = "0.3.0"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }

View file

@ -133,7 +133,8 @@ impl Configuration {
use self::error::ConfigErrorKind as CEK; use self::error::ConfigErrorKind as CEK;
use self::error::MapErrInto; use self::error::MapErrInto;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use libimagstore::toml_ext::TomlValueExt;
use toml_query::read::TomlValueReadExt;
v.into_iter() v.into_iter()
.map(|s| { debug!("Trying to process '{}'", s); s }) .map(|s| { debug!("Trying to process '{}'", s); s })
@ -170,10 +171,10 @@ impl Configuration {
/// Returns None if string cannot be converted. /// Returns None if string cannot be converted.
/// ///
/// Arrays and Tables are not supported and will yield `None`. /// Arrays and Tables are not supported and will yield `None`.
fn into_value(value: Value, s: String) -> Option<Value> { fn into_value(value: &Value, s: String) -> Option<Value> {
use std::str::FromStr; use std::str::FromStr;
match value { match *value {
Value::String(_) => Some(Value::String(s)), Value::String(_) => Some(Value::String(s)),
Value::Integer(_) => FromStr::from_str(&s[..]).ok().map(Value::Integer), Value::Integer(_) => FromStr::from_str(&s[..]).ok().map(Value::Integer),
Value::Float(_) => FromStr::from_str(&s[..]).ok().map(Value::Float), Value::Float(_) => FromStr::from_str(&s[..]).ok().map(Value::Float),

View file

@ -37,11 +37,11 @@
extern crate itertools; extern crate itertools;
#[cfg(unix)] extern crate xdg_basedir; #[cfg(unix)] extern crate xdg_basedir;
extern crate env_logger; extern crate env_logger;
extern crate tempfile;
extern crate ansi_term; extern crate ansi_term;
extern crate clap; extern crate clap;
extern crate toml; extern crate toml;
extern crate toml_query;
#[macro_use] extern crate is_match; #[macro_use] extern crate is_match;
extern crate libimagstore; extern crate libimagstore;

View file

@ -14,7 +14,6 @@ repository = "https://github.com/matthiasbeyer/imag"
homepage = "http://imag-pim.org" homepage = "http://imag-pim.org"
[dependencies] [dependencies]
fs2 = "0.4"
glob = "0.2.11" glob = "0.2.11"
lazy_static = "0.2.*" lazy_static = "0.2.*"
log = "0.3" log = "0.3"
@ -22,9 +21,7 @@ regex = "0.2"
semver = "0.5" semver = "0.5"
toml = "^0.4" toml = "^0.4"
version = "2.0.1" version = "2.0.1"
crossbeam = "0.2.*"
walkdir = "1.0.*" walkdir = "1.0.*"
itertools = "0.6.*"
is-match = "0.1" is-match = "0.1"
serde = "1.0" serde = "1.0"
serde_json = "1.0" serde_json = "1.0"

View file

@ -80,7 +80,7 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
match *self { match *self {
InMemoryFileAbstractionInstance { ref absent_path, .. } => { InMemoryFileAbstractionInstance { ref absent_path, .. } => {
let mut mtx = self.fs_abstraction.lock().expect("Locking Mutex failed"); 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()); let _ = backend.insert(absent_path.clone(), buf.clone());
return Ok(()); return Ok(());
}, },
@ -130,7 +130,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> { fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> {
debug!("Copying : {:?} -> {:?}", from, to); debug!("Copying : {:?} -> {:?}", from, to);
let mut mtx = self.backend().lock().expect("Locking Mutex failed"); 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())); let a = try!(backend.get(from).cloned().ok_or(SEK::FileNotFound.into_error()));
backend.insert(to.clone(), a); backend.insert(to.clone(), a);
@ -141,7 +141,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> { fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> {
debug!("Renaming: {:?} -> {:?}", from, to); debug!("Renaming: {:?} -> {:?}", from, to);
let mut mtx = self.backend().lock().expect("Locking Mutex failed"); 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())); let a = try!(backend.get(from).cloned().ok_or(SEK::FileNotFound.into_error()));
backend.insert(to.clone(), a); backend.insert(to.clone(), a);
@ -164,7 +164,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
fn fill<'a>(&'a mut self, mut d: Drain) -> Result<(), SE> { fn fill<'a>(&'a mut self, mut d: Drain) -> Result<(), SE> {
debug!("Draining into : {:?}", self); debug!("Draining into : {:?}", self);
let mut mtx = try!(self.backend().lock().map_err(|_| SEK::LockError.into_error())); 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() { for (path, element) in d.iter() {
debug!("Drain into {:?}: {:?}", self, path); debug!("Drain into {:?}: {:?}", self, path);

View file

@ -143,7 +143,7 @@ impl<W: Write, M: Mapper> FileAbstraction for StdoutFileAbstraction<W, M> {
fn fill(&mut self, mut d: Drain) -> Result<(), SE> { fn fill(&mut self, mut d: Drain) -> Result<(), SE> {
debug!("Draining into : {:?}", self); debug!("Draining into : {:?}", self);
let mut mtx = try!(self.backend().lock().map_err(|_| SEK::IoError.into_error())); 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() { for (path, element) in d.iter() {
debug!("Drain into {:?}: {:?}", self, path); debug!("Drain into {:?}: {:?}", self, path);

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -26,6 +27,7 @@
unused_allocation, unused_allocation,
unused_import_braces, unused_import_braces,
unused_imports, unused_imports,
unused_must_use,
unused_mut, unused_mut,
unused_qualifications, unused_qualifications,
while_true, while_true,
@ -33,18 +35,14 @@
#[macro_use] extern crate log; #[macro_use] extern crate log;
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate fs2;
extern crate glob; extern crate glob;
#[macro_use] extern crate lazy_static; #[macro_use] extern crate lazy_static;
extern crate regex; extern crate regex;
extern crate toml; extern crate toml;
#[cfg(test)] extern crate tempdir; #[cfg(test)] extern crate tempdir;
extern crate semver; extern crate semver;
extern crate crossbeam;
extern crate walkdir; extern crate walkdir;
extern crate itertools;
#[macro_use] extern crate is_match; #[macro_use] extern crate is_match;
extern crate serde;
extern crate serde_json; extern crate serde_json;
#[macro_use] extern crate serde_derive; #[macro_use] extern crate serde_derive;
@ -58,5 +56,4 @@ pub mod error;
pub mod store; pub mod store;
mod configuration; mod configuration;
pub mod file_abstraction; pub mod file_abstraction;
pub mod toml_ext;

View file

@ -18,6 +18,7 @@
// //
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::BTreeMap;
use std::ops::Drop; use std::ops::Drop;
use std::path::PathBuf; use std::path::PathBuf;
use std::result::Result as RResult; use std::result::Result as RResult;
@ -32,15 +33,16 @@ use std::fmt::Debug;
use std::fmt::Error as FMTError; use std::fmt::Error as FMTError;
use toml::Value; use toml::Value;
use toml::value::Table;
use glob::glob; use glob::glob;
use walkdir::WalkDir; use walkdir::WalkDir;
use walkdir::Iter as WalkDirIter; 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 error::MapErrInto;
use storeid::{IntoStoreId, StoreId, StoreIdIterator}; use storeid::{IntoStoreId, StoreId, StoreIdIterator};
use file_abstraction::FileAbstractionInstance; use file_abstraction::FileAbstractionInstance;
use toml_ext::*;
// We re-export the following things so tests can use them // We re-export the following things so tests can use them
pub use file_abstraction::FileAbstraction; pub use file_abstraction::FileAbstraction;
pub use file_abstraction::FSFileAbstraction; pub use file_abstraction::FSFileAbstraction;
@ -450,7 +452,7 @@ impl Store {
.map_err(|_| SE::new(SEK::LockPoisoned, None)) .map_err(|_| SE::new(SEK::LockPoisoned, None))
.and_then(|mut es| { .and_then(|mut es| {
let new_se = try!(StoreEntry::new(id.clone(), &self.backend)); 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(); let entry = se.get_entry();
se.status = StoreEntryStatus::Borrowed; se.status = StoreEntryStatus::Borrowed;
entry entry
@ -562,7 +564,7 @@ impl Store {
Ok(e) => e, 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."); assert!(se.is_borrowed(), "Tried to update a non borrowed entry.");
@ -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<Value, ParserError>;
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<Value, ParserError> {
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::<String, Value>::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<Table, ParserError> {
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)] #[cfg(test)]
mod test { mod test {
@ -1122,13 +1214,14 @@ mod test {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use storeid::StoreId; use storeid::StoreId;
use store::has_main_section;
use store::has_imag_version_in_main_section;
use store::verify_header_consistency;
use toml::Value; use toml::Value;
#[test] #[test]
fn test_imag_section() { fn test_imag_section() {
use toml_ext::has_main_section;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
map.insert("imag".into(), Value::Table(BTreeMap::new())); map.insert("imag".into(), Value::Table(BTreeMap::new()));
@ -1137,8 +1230,6 @@ mod test {
#[test] #[test]
fn test_imag_invalid_section_type() { fn test_imag_invalid_section_type() {
use toml_ext::has_main_section;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
map.insert("imag".into(), Value::Boolean(false)); map.insert("imag".into(), Value::Boolean(false));
@ -1147,8 +1238,6 @@ mod test {
#[test] #[test]
fn test_imag_abscent_main_section() { fn test_imag_abscent_main_section() {
use toml_ext::has_main_section;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
map.insert("not_imag".into(), Value::Boolean(false)); map.insert("not_imag".into(), Value::Boolean(false));
@ -1157,8 +1246,6 @@ mod test {
#[test] #[test]
fn test_main_section_without_version() { fn test_main_section_without_version() {
use toml_ext::has_imag_version_in_main_section;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
map.insert("imag".into(), Value::Table(BTreeMap::new())); map.insert("imag".into(), Value::Table(BTreeMap::new()));
@ -1167,8 +1254,6 @@ mod test {
#[test] #[test]
fn test_main_section_with_version() { fn test_main_section_with_version() {
use toml_ext::has_imag_version_in_main_section;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
let mut sub = BTreeMap::new(); let mut sub = BTreeMap::new();
sub.insert("version".into(), Value::String("0.0.0".into())); sub.insert("version".into(), Value::String("0.0.0".into()));
@ -1179,8 +1264,6 @@ mod test {
#[test] #[test]
fn test_main_section_with_version_in_wrong_type() { 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 map = BTreeMap::new();
let mut sub = BTreeMap::new(); let mut sub = BTreeMap::new();
sub.insert("version".into(), Value::Boolean(false)); sub.insert("version".into(), Value::Boolean(false));
@ -1191,8 +1274,6 @@ mod test {
#[test] #[test]
fn test_verification_good() { fn test_verification_good() {
use toml_ext::verify_header_consistency;
let mut header = BTreeMap::new(); let mut header = BTreeMap::new();
let sub = { let sub = {
let mut sub = BTreeMap::new(); let mut sub = BTreeMap::new();
@ -1208,8 +1289,6 @@ mod test {
#[test] #[test]
fn test_verification_invalid_versionstring() { fn test_verification_invalid_versionstring() {
use toml_ext::verify_header_consistency;
let mut header = BTreeMap::new(); let mut header = BTreeMap::new();
let sub = { let sub = {
let mut sub = BTreeMap::new(); let mut sub = BTreeMap::new();
@ -1226,8 +1305,6 @@ mod test {
#[test] #[test]
fn test_verification_current_version() { fn test_verification_current_version() {
use toml_ext::verify_header_consistency;
let mut header = BTreeMap::new(); let mut header = BTreeMap::new();
let sub = { let sub = {
let mut sub = BTreeMap::new(); let mut sub = BTreeMap::new();

View file

@ -1,894 +0,0 @@
//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> 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<String, Value>;
pub trait TomlValueExt {
fn insert_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result<bool>;
fn set_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result<Option<Value>>;
fn read_with_sep(&self, spec: &str, splitchr: char) -> Result<Option<Value>>;
fn delete_with_sep(&mut self, spec: &str, splitchr: char) -> Result<Option<Value>>;
#[inline]
fn insert(&mut self, spec: &str, v: Value) -> Result<bool> {
self.insert_with_sep(spec, '.', v)
}
#[inline]
fn set(&mut self, spec: &str, v: Value) -> Result<Option<Value>> {
self.set_with_sep(spec, '.', v)
}
#[inline]
fn read(&self, spec: &str) -> Result<Option<Value>> {
self.read_with_sep(spec, '.')
}
#[inline]
fn delete(&mut self, spec: &str) -> Result<Option<Value>> {
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<bool> {
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<Option<Value>> {
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<Option<Value>> {
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<Option<Value>> {
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<Token> = 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<Vec<Token>> {
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<Token>) -> Result<&mut Value> {
use std::vec::IntoIter;
fn walk_iter<'a>(v: Result<&'a mut Value>, i: &mut IntoIter<Token>) -> 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<T> = RResult<T, ParserError>;
/// 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<Value>;
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<Value> {
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::<String, Value>::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<Table> {
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;
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 });
}
}

View file

@ -23,8 +23,8 @@ use toml::Value;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use store::Result; use store::Result;
use store::Header;
use error::StoreErrorKind as SEK; use error::StoreErrorKind as SEK;
use toml_ext::Header;
#[cfg(feature = "early-panic")] #[cfg(feature = "early-panic")]
#[macro_export] #[macro_export]

View file

@ -14,7 +14,6 @@ repository = "https://github.com/matthiasbeyer/imag"
homepage = "http://imag-pim.org" homepage = "http://imag-pim.org"
[dependencies] [dependencies]
semver = "0.5"
url = "1.2" url = "1.2"
regex = "0.1" regex = "0.1"

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -26,12 +27,12 @@
unused_allocation, unused_allocation,
unused_import_braces, unused_import_braces,
unused_imports, unused_imports,
unused_must_use,
unused_mut, unused_mut,
unused_qualifications, unused_qualifications,
while_true, while_true,
)] )]
extern crate semver;
extern crate url; extern crate url;
extern crate regex; extern crate regex;

View file

@ -17,7 +17,6 @@ homepage = "http://imag-pim.org"
log = "0.3" log = "0.3"
toml = "0.4.*" toml = "0.4.*"
toml-query = "0.3.*" toml-query = "0.3.*"
semver = "0.5"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }

View file

@ -75,8 +75,8 @@ impl<'a> Counter<'a> {
let mut lockentry = try!(store.create(id).map_err_into(CEK::StoreWriteError)); let mut lockentry = try!(store.create(id).map_err_into(CEK::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(&String::from("counter"), Value::Table(BTreeMap::new())); let setres = header.set(&String::from("counter"), Value::Table(BTreeMap::new()));
if setres.is_err() { if setres.is_err() {
return Err(CEK::StoreWriteError.into_error()); return Err(CEK::StoreWriteError.into_error());
@ -103,7 +103,7 @@ impl<'a> Counter<'a> {
self.unit = unit; self.unit = unit;
if let Some(u) = self.unit.clone() { 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)); let setres = header.set(&String::from("counter.unit"), Value::String(u.0));
if setres.is_err() { if setres.is_err() {
self.unit = None; self.unit = None;
@ -114,7 +114,7 @@ impl<'a> Counter<'a> {
} }
pub fn inc(&mut self) -> Result<()> { 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"); let query = String::from("counter.value");
match try!(header.read(&query).map_err_into(CEK::StoreReadError)) { match try!(header.read(&query).map_err_into(CEK::StoreReadError)) {
Some(&Value::Integer(i)) => { Some(&Value::Integer(i)) => {
@ -127,7 +127,7 @@ impl<'a> Counter<'a> {
} }
pub fn dec(&mut self) -> Result<()> { 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"); let query = String::from("counter.value");
match try!(header.read(&query).map_err_into(CEK::StoreReadError)) { match try!(header.read(&query).map_err_into(CEK::StoreReadError)) {
Some(&Value::Integer(i)) => { Some(&Value::Integer(i)) => {
@ -144,8 +144,10 @@ impl<'a> Counter<'a> {
} }
pub fn set(&mut self, v: i64) -> Result<()> { pub fn set(&mut self, v: i64) -> Result<()> {
let mut header = self.fle.deref_mut().get_header_mut(); self.fle
header.set(&String::from("counter.value"), Value::Integer(v)) .deref_mut()
.get_header_mut()
.set(&String::from("counter.value"), Value::Integer(v))
.map_err_into(CEK::StoreWriteError) .map_err_into(CEK::StoreWriteError)
.map(|_| ()) .map(|_| ())
} }

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -26,6 +27,7 @@
unused_allocation, unused_allocation,
unused_import_braces, unused_import_braces,
unused_imports, unused_imports,
unused_must_use,
unused_mut, unused_mut,
unused_qualifications, unused_qualifications,
while_true, while_true,
@ -34,7 +36,6 @@
extern crate toml; extern crate toml;
extern crate toml_query; extern crate toml_query;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate semver;
#[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagerror;

View file

@ -16,15 +16,12 @@ homepage = "http://imag-pim.org"
[dependencies] [dependencies]
chrono = "0.4" chrono = "0.4"
log = "0.3" log = "0.3"
semver = "0.5"
toml = "0.4.*" toml = "0.4.*"
toml-query = "0.3.*" toml-query = "0.3.*"
regex = "0.1"
itertools = "0.5" itertools = "0.5"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } 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" } libimagentryedit = { version = "0.4.0", path = "../../../lib/entry/libimagentryedit" }
libimagentryview = { version = "0.4.0", path = "../../../lib/entry/libimagentryview" } libimagentryview = { version = "0.4.0", path = "../../../lib/entry/libimagentryview" }

View file

@ -35,10 +35,8 @@
extern crate chrono; extern crate chrono;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate semver;
extern crate toml; extern crate toml;
extern crate toml_query; extern crate toml_query;
extern crate regex;
extern crate itertools; extern crate itertools;
#[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagstore;
@ -46,7 +44,6 @@ extern crate itertools;
extern crate libimagentryedit; extern crate libimagentryedit;
extern crate libimagentryview; extern crate libimagentryview;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagutil;
module_entry_path_mod!("diary"); module_entry_path_mod!("diary");

View file

@ -16,8 +16,6 @@ homepage = "http://imag-pim.org"
[dependencies] [dependencies]
log = "0.3" log = "0.3"
email = "0.0.17" email = "0.0.17"
semver = "0.5"
toml = "0.4.*"
filters = "0.1.*" filters = "0.1.*"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }

View file

@ -28,7 +28,6 @@ use mail::Mail;
use result::Result; use result::Result;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagentryref::reference::Ref;
use std::marker::PhantomData; use std::marker::PhantomData;

View file

@ -17,10 +17,24 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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; #[macro_use] extern crate log;
extern crate email; extern crate email;
extern crate semver;
extern crate toml;
extern crate filters; extern crate filters;
#[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagerror;

View file

@ -55,6 +55,7 @@ impl<'a> Mail<'a> {
/// Imports a mail from the Path passed /// Imports a mail from the Path passed
pub fn import_from_path<P: AsRef<Path>>(store: &Store, p: P) -> Result<Mail> { pub fn import_from_path<P: AsRef<Path>>(store: &Store, p: P) -> Result<Mail> {
debug!("Importing Mail from path");
let h = MailHasher::new(); let h = MailHasher::new();
let f = RefFlags::default().with_content_hashing(true).with_permission_tracking(false); let f = RefFlags::default().with_content_hashing(true).with_permission_tracking(false);
let p = PathBuf::from(p.as_ref()); let p = PathBuf::from(p.as_ref());
@ -62,6 +63,7 @@ impl<'a> Mail<'a> {
store.create_with_hasher(p, f, h) store.create_with_hasher(p, f, h)
.map_err_into(MEK::RefCreationError) .map_err_into(MEK::RefCreationError)
.and_then(|reference| { .and_then(|reference| {
debug!("Build reference file: {:?}", reference);
reference.fs_file() reference.fs_file()
.map_err_into(MEK::RefHandlingError) .map_err_into(MEK::RefHandlingError)
.and_then(|path| File::open(path).map_err_into(MEK::IOError)) .and_then(|path| File::open(path).map_err_into(MEK::IOError))
@ -78,6 +80,7 @@ impl<'a> Mail<'a> {
/// Opens a mail by the passed hash /// Opens a mail by the passed hash
pub fn open<S: AsRef<str>>(store: &Store, hash: S) -> Result<Option<Mail>> { pub fn open<S: AsRef<str>>(store: &Store, hash: S) -> Result<Option<Mail>> {
debug!("Opening Mail by Hash");
store.get_by_hash(String::from(hash.as_ref())) store.get_by_hash(String::from(hash.as_ref()))
.map_err_into(MEK::FetchByHashError) .map_err_into(MEK::FetchByHashError)
.map_err_into(MEK::FetchError) .map_err_into(MEK::FetchError)
@ -104,6 +107,7 @@ impl<'a> Mail<'a> {
} }
pub fn get_field(&self, field: &str) -> Result<Option<String>> { pub fn get_field(&self, field: &str) -> Result<Option<String>> {
debug!("Getting field in mail: {:?}", field);
self.1 self.1
.parsed() .parsed()
.map_err_into(MEK::MailParsingError) .map_err_into(MEK::MailParsingError)

View file

@ -14,12 +14,11 @@ repository = "https://github.com/matthiasbeyer/imag"
homepage = "http://imag-pim.org" homepage = "http://imag-pim.org"
[dependencies] [dependencies]
semver = "0.5"
log = "0.3" log = "0.3"
toml = "^0.4" toml = "^0.4"
toml-query = "0.3.0"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" }
libimagentryedit = { version = "0.4.0", path = "../../../lib/entry/libimagentryedit" } libimagentryedit = { version = "0.4.0", path = "../../../lib/entry/libimagentryedit" }
libimagentrytag = { version = "0.4.0", path = "../../../lib/entry/libimagentrytag" }

View file

@ -34,14 +34,13 @@
)] )]
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate semver;
extern crate toml; extern crate toml;
extern crate toml_query;
extern crate libimagrt; extern crate libimagrt;
#[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagerror;
extern crate libimagentryedit; extern crate libimagentryedit;
extern crate libimagentrytag;
module_entry_path_mod!("notes"); module_entry_path_mod!("notes");

View file

@ -30,7 +30,9 @@ use libimagstore::storeid::StoreId;
use libimagstore::storeid::StoreIdIterator; use libimagstore::storeid::StoreIdIterator;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::toml_ext::TomlValueExt;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use module_path::ModuleEntryPath; use module_path::ModuleEntryPath;
use result::Result; use result::Result;
@ -56,10 +58,10 @@ impl<'a> Note<'a> {
.map_err_into(NEK::StoreWriteError)); .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())); let setres = header.set("note", Value::Table(BTreeMap::new()));
if setres.is_err() { if setres.is_err() {
let kind = NEK::StoreWriteError; let kind = NEK::StoreWriteError;
@ -83,8 +85,9 @@ impl<'a> Note<'a> {
} }
pub fn set_name(&mut self, n: String) -> Result<()> { pub fn set_name(&mut self, n: String) -> Result<()> {
let mut header = self.entry.get_header_mut(); self.entry
header.set("note.name", Value::String(n)) .get_header_mut()
.set("note.name", Value::String(n))
.map_err(|e| NE::new(NEK::StoreWriteError, Some(Box::new(e)))) .map_err(|e| NE::new(NEK::StoreWriteError, Some(Box::new(e))))
.map(|_| ()) .map(|_| ())
} }
@ -92,7 +95,7 @@ impl<'a> Note<'a> {
pub fn get_name(&self) -> Result<String> { pub fn get_name(&self) -> Result<String> {
let header = self.entry.get_header(); let header = self.entry.get_header();
match header.read("note.name") { match header.read("note.name") {
Ok(Some(Value::String(s))) => Ok(String::from(s)), Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
Ok(_) => { Ok(_) => {
let e = NE::new(NEK::HeaderTypeError, None); let e = NE::new(NEK::HeaderTypeError, None);
Err(NE::new(NEK::StoreReadError, Some(Box::new(e)))) Err(NE::new(NEK::StoreReadError, Some(Box::new(e))))

View file

@ -17,10 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// //
use result::Result;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use filters::filter::Filter;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;

View file

@ -30,10 +30,7 @@ mod test {
use libimagstore::store::Store; use libimagstore::store::Store;
use super::create::*;
use super::get::*;
use super::setendtime::*; use super::setendtime::*;
use super::storeid::*;
use super::tag::*; use super::tag::*;
fn get_store() -> Store { fn get_store() -> Store {
@ -53,7 +50,7 @@ mod test {
let iter = tags.into_iter().map(String::from); 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_storeids(now)
.create_entries(&store) .create_entries(&store)
.set_end_time(then); .set_end_time(then);

View file

@ -17,6 +17,22 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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 filters;
extern crate chrono; extern crate chrono;
extern crate toml; extern crate toml;

View file

@ -14,15 +14,12 @@ repository = "https://github.com/matthiasbeyer/imag"
homepage = "http://imag-pim.org" homepage = "http://imag-pim.org"
[dependencies] [dependencies]
semver = "0.2"
task-hookrs = "0.2.2" task-hookrs = "0.2.2"
uuid = "0.3" uuid = "0.3"
toml = "0.4.*" toml = "0.4.*"
toml-query = "0.3.*" toml-query = "0.3.*"
is-match = "0.1.*"
log = "0.3" log = "0.3"
serde_json = "0.8" serde_json = "0.8"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }

View file

@ -22,7 +22,8 @@ generate_error_module!(
ConversionError => "Conversion Error", ConversionError => "Conversion Error",
StoreError => "Store Error", StoreError => "Store Error",
StoreIdError => "Store Id handling error", StoreIdError => "Store Id handling error",
ImportError => "Error importing" ImportError => "Error importing",
UTF8Error => "Encountered non-UTF8 characters while reading input"
); );
); );

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -26,22 +27,20 @@
unused_allocation, unused_allocation,
unused_import_braces, unused_import_braces,
unused_imports, unused_imports,
unused_must_use,
unused_mut, unused_mut,
unused_qualifications, unused_qualifications,
while_true, while_true,
)] )]
extern crate semver;
extern crate uuid; extern crate uuid;
extern crate toml; extern crate toml;
extern crate toml_query; extern crate toml_query;
#[macro_use] extern crate is_match;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate serde_json; extern crate serde_json;
#[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagerror;
extern crate libimagutil;
extern crate task_hookrs; extern crate task_hookrs;
module_entry_path_mod!("todo"); module_entry_path_mod!("todo");

View file

@ -48,7 +48,7 @@ impl<'a> Task<'a> {
pub fn import<R: BufRead>(store: &'a Store, mut r: R) -> Result<(Task<'a>, String, Uuid)> { pub fn import<R: BufRead>(store: &'a Store, mut r: R) -> Result<(Task<'a>, String, Uuid)> {
let mut line = String::new(); 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()) import_task(&line.as_str())
.map_err_into(TEK::ImportError) .map_err_into(TEK::ImportError)
.and_then(|t| { .and_then(|t| {
@ -70,7 +70,7 @@ impl<'a> Task<'a> {
where R: BufRead where R: BufRead
{ {
let mut line = String::new(); 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) Task::get_from_string(store, line)
} }
@ -104,7 +104,7 @@ impl<'a> Task<'a> {
/// implicitely create the task if it does not exist. /// implicitely create the task if it does not exist.
pub fn retrieve_from_import<R: BufRead>(store: &'a Store, mut r: R) -> Result<Task<'a>> { pub fn retrieve_from_import<R: BufRead>(store: &'a Store, mut r: R) -> Result<Task<'a>> {
let mut line = String::new(); 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) Task::retrieve_from_string(store, line)
} }
@ -220,13 +220,6 @@ impl<'a> IntoTask<'a> for TTask {
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt; use toml_query::set::TomlValueSetExt;
// Helper for toml_query::read::TomlValueReadExt::read() return value, which does only
// return Result<T> instead of Result<Option<T>>, 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(); let uuid = self.uuid();
ModuleEntryPath::new(format!("taskwarrior/{}", uuid)) ModuleEntryPath::new(format!("taskwarrior/{}", uuid))
.into_storeid() .into_storeid()
@ -236,7 +229,7 @@ impl<'a> IntoTask<'a> for TTask {
.map_err_into(TEK::StoreError) .map_err_into(TEK::StoreError)
.and_then(|mut fle| { .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() { if try!(hdr.read("todo").map_err_into(TEK::StoreError)).is_none() {
try!(hdr try!(hdr
.set("todo", Value::Table(BTreeMap::new())) .set("todo", Value::Table(BTreeMap::new()))

View file

@ -10,12 +10,11 @@ readme = "../README.md"
license = "LGPL-2.1" license = "LGPL-2.1"
[dependencies] [dependencies]
uuid = { version = "0.3.1", features = ["v4"] }
lazy_static = "0.1.15" lazy_static = "0.1.15"
toml = "^0.4" toml = "^0.4"
toml-query = "0.3.0"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagnotes = { version = "0.4.0", path = "../../../lib/domain/libimagnotes" } libimagnotes = { version = "0.4.0", path = "../../../lib/domain/libimagnotes" }
libimagentrylink = { version = "0.4.0", path = "../../../lib/entry/libimagentrylink" } libimagentrylink = { version = "0.4.0", path = "../../../lib/entry/libimagentrylink" }
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }

View file

@ -24,10 +24,12 @@ use toml::Value;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::toml_ext::TomlValueExt;
use libimagentrylink::internal::InternalLinker; use libimagentrylink::internal::InternalLinker;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use toml_query::read::TomlValueReadExt;
use toml_query::insert::TomlValueInsertExt;
use result::Result; use result::Result;
use error::AnnotationErrorKind as AEK; use error::AnnotationErrorKind as AEK;
use error::MapErrInto; use error::MapErrInto;
@ -53,14 +55,8 @@ impl Annotateable for Entry {
.and_then(|mut anno| { .and_then(|mut anno| {
anno.get_header_mut() anno.get_header_mut()
.insert("annotation.is_annotation", Value::Boolean(true)) .insert("annotation.is_annotation", Value::Boolean(true))
.map_err_into(AEK::StoreWriteError) .map_err_into(AEK::HeaderWriteError)
.and_then(|succeeded| { .map(|_| anno)
if succeeded {
Ok(anno)
} else {
Err(AEK::HeaderWriteError.into_error())
}
})
}) })
.and_then(|mut anno| { .and_then(|mut anno| {
anno.add_internal_link(self) anno.add_internal_link(self)
@ -74,9 +70,9 @@ impl Annotateable for Entry {
.read("annotation.is_annotation") .read("annotation.is_annotation")
.map_err_into(AEK::StoreReadError) .map_err_into(AEK::StoreReadError)
.and_then(|res| match res { .and_then(|res| match res {
Some(Value::Boolean(b)) => Ok(b), Some(&Value::Boolean(b)) => Ok(b),
None => Ok(false), None => Ok(false),
_ => Err(AEK::HeaderTypeError.into_error()), _ => Err(AEK::HeaderTypeError.into_error()),
}) })
} }

View file

@ -68,7 +68,8 @@ impl<'a> AnnotationFetcher<'a> for Store {
pub mod iter { pub mod iter {
use toml::Value; use toml::Value;
use libimagstore::toml_ext::TomlValueExt; use toml_query::read::TomlValueReadExt;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use libimagnotes::note::Note; use libimagnotes::note::Note;
use libimagnotes::note::NoteIterator; use libimagnotes::note::NoteIterator;
@ -95,10 +96,9 @@ pub mod iter {
loop { loop {
match self.0.next() { match self.0.next() {
Some(Ok(note)) => { Some(Ok(note)) => {
let hdr = note.get_header().read("annotation.is_annotation"); match note.get_header().read("annotation.is_annotation") {
match hdr {
Ok(None) => continue, // not an 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())), Ok(Some(_)) => return Some(Err(AEK::HeaderTypeError.into_error())),
Err(e) => return Some(Err(e).map_err_into(AEK::HeaderReadError)), Err(e) => return Some(Err(e).map_err_into(AEK::HeaderReadError)),
} }

View file

@ -17,14 +17,29 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// //
extern crate uuid; #![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; extern crate toml;
extern crate toml_query;
#[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagerror;
#[macro_use] extern crate libimagstore; extern crate libimagstore;
extern crate libimagentrylink; extern crate libimagentrylink;
extern crate libimagnotes; extern crate libimagnotes;
extern crate libimagutil;
pub mod annotateable; pub mod annotateable;
pub mod annotation_fetcher; pub mod annotation_fetcher;

View file

@ -17,6 +17,22 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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_query;
extern crate toml; extern crate toml;
#[macro_use] #[macro_use]

View file

@ -21,8 +21,4 @@ toml = "0.4"
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }
[dev-dependencies]
is-match = "0.1"

View file

@ -17,6 +17,22 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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; #[macro_use] extern crate lazy_static;
extern crate chrono; extern crate chrono;
extern crate toml_query; extern crate toml_query;
@ -24,10 +40,6 @@ extern crate toml;
#[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagerror;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagutil;
#[cfg(test)]
#[macro_use] extern crate is_match;
pub mod datepath; pub mod datepath;
pub mod datetime; pub mod datetime;

View file

@ -17,6 +17,22 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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; #[macro_use] extern crate libimagerror;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagrt; extern crate libimagrt;

View file

@ -21,6 +21,7 @@ log = "0.3"
regex = "0.2" regex = "0.2"
semver = "0.5.*" semver = "0.5.*"
toml = "^0.4" toml = "^0.4"
toml-query = "0.3.0"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagentrytag = { version = "0.4.0", path = "../../../lib/entry/libimagentrytag" } libimagentrytag = { version = "0.4.0", path = "../../../lib/entry/libimagentrytag" }

View file

@ -32,8 +32,8 @@ struct EqPred {
impl Predicate for EqPred { impl Predicate for EqPred {
fn evaluate(&self, v: Value) -> bool { fn evaluate(&self, v: &Value) -> bool {
self.expected == v self.expected == *v
} }
} }

View file

@ -18,10 +18,11 @@
// //
use libimagstore::store::Entry; 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 builtin::header::field_path::FieldPath;
use filters::filter::Filter;
pub struct FieldExists { pub struct FieldExists {
header_field_path: FieldPath, header_field_path: FieldPath,

View file

@ -33,10 +33,10 @@ struct EqGrep{
impl Predicate for EqGrep { impl Predicate for EqGrep {
fn evaluate(&self, v: Value) -> bool { fn evaluate(&self, v: &Value) -> bool {
match v { match *v {
Value::String(s) => self.regex.captures(&s[..]).is_some(), Value::String(ref s) => self.regex.captures(&s[..]).is_some(),
_ => false, _ => false,
} }
} }

View file

@ -32,17 +32,17 @@ struct EqGt {
impl Predicate for EqGt { impl Predicate for EqGt {
fn evaluate(&self, v: Value) -> bool { fn evaluate(&self, v: &Value) -> bool {
match self.comp { match self.comp {
Value::Integer(i) => { Value::Integer(i) => {
match v { match *v {
Value::Integer(j) => i > j, Value::Integer(j) => i > j,
Value::Float(f) => (i as f64) > f, Value::Float(f) => (i as f64) > f,
_ => false, _ => false,
} }
}, },
Value::Float(f) => { Value::Float(f) => {
match v { match *v {
Value::Integer(i) => f > (i as f64), Value::Integer(i) => f > (i as f64),
Value::Float(d) => f > d, Value::Float(d) => f > d,
_ => false, _ => false,

View file

@ -18,7 +18,7 @@
// //
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagstore::toml_ext::TomlValueExt; use toml_query::read::TomlValueReadExt;
use builtin::header::field_path::FieldPath; use builtin::header::field_path::FieldPath;
use filters::filter::Filter; use filters::filter::Filter;
@ -46,12 +46,12 @@ impl Filter<Entry> for FieldIsEmpty {
.read(&self.header_field_path[..]) .read(&self.header_field_path[..])
.map(|v| { .map(|v| {
match v { match v {
Some(Value::Array(a)) => a.is_empty(), Some(&Value::Array(ref a)) => a.is_empty(),
Some(Value::String(s)) => s.is_empty(), Some(&Value::String(ref s)) => s.is_empty(),
Some(Value::Table(t)) => t.is_empty(), Some(&Value::Table(ref t)) => t.is_empty(),
Some(Value::Boolean(_)) | Some(&Value::Boolean(_)) |
Some(Value::Float(_)) | Some(&Value::Float(_)) |
Some(Value::Integer(_)) => false, Some(&Value::Integer(_)) => false,
_ => true, _ => true,
} }
}) })

View file

@ -58,8 +58,8 @@ struct IsTypePred {
impl Predicate for IsTypePred { impl Predicate for IsTypePred {
fn evaluate(&self, v: Value) -> bool { fn evaluate(&self, v: &Value) -> bool {
self.ty.matches(&v) self.ty.matches(v)
} }
} }

View file

@ -32,17 +32,17 @@ struct EqLt {
impl Predicate for EqLt { impl Predicate for EqLt {
fn evaluate(&self, v: Value) -> bool { fn evaluate(&self, v: &Value) -> bool {
match self.comp { match self.comp {
Value::Integer(i) => { Value::Integer(i) => {
match v { match *v {
Value::Integer(j) => i < j, Value::Integer(j) => i < j,
Value::Float(f) => (i as f64) < f, Value::Float(f) => (i as f64) < f,
_ => false, _ => false,
} }
}, },
Value::Float(f) => { Value::Float(f) => {
match v { match *v {
Value::Integer(i) => f < (i as f64), Value::Integer(i) => f < (i as f64),
Value::Float(d) => f < d, Value::Float(d) => f < d,
_ => false, _ => false,

View file

@ -18,7 +18,8 @@
// //
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagstore::toml_ext::TomlValueExt;
use toml_query::read::TomlValueReadExt;
use builtin::header::field_path::FieldPath; use builtin::header::field_path::FieldPath;
use filters::filter::Filter; use filters::filter::Filter;
@ -26,7 +27,7 @@ use filters::filter::Filter;
use toml::Value; use toml::Value;
pub trait Predicate { 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 /// Check whether certain header field in a entry is equal to a value

View file

@ -21,8 +21,8 @@ use semver::Version;
use toml::Value; use toml::Value;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagstore::toml_ext::TomlValueExt;
use toml_query::read::TomlValueReadExt;
use filters::filter::Filter; use filters::filter::Filter;
pub struct VersionEq { pub struct VersionEq {
@ -44,8 +44,8 @@ impl Filter<Entry> for VersionEq {
.read("imag.version") .read("imag.version")
.map(|val| { .map(|val| {
val.map_or(false, |v| { val.map_or(false, |v| {
match v { match *v {
Value::String(s) => { Value::String(ref s) => {
match Version::parse(&s[..]) { match Version::parse(&s[..]) {
Ok(v) => v == self.version, Ok(v) => v == self.version,
_ => false _ => false

View file

@ -21,8 +21,8 @@ use semver::Version;
use toml::Value; use toml::Value;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagstore::toml_ext::TomlValueExt;
use toml_query::read::TomlValueReadExt;
use filters::filter::Filter; use filters::filter::Filter;
pub struct VersionGt { pub struct VersionGt {
@ -44,8 +44,8 @@ impl Filter<Entry> for VersionGt {
.read("imag.version") .read("imag.version")
.map(|val| { .map(|val| {
val.map_or(false, |v| { val.map_or(false, |v| {
match v { match *v {
Value::String(s) => { Value::String(ref s) => {
match Version::parse(&s[..]) { match Version::parse(&s[..]) {
Ok(v) => v > self.version, Ok(v) => v > self.version,
_ => false _ => false

View file

@ -21,8 +21,8 @@ use semver::Version;
use toml::Value; use toml::Value;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagstore::toml_ext::TomlValueExt;
use toml_query::read::TomlValueReadExt;
use filters::filter::Filter; use filters::filter::Filter;
pub struct VersionLt { pub struct VersionLt {
@ -44,8 +44,8 @@ impl Filter<Entry> for VersionLt {
.read("imag.version") .read("imag.version")
.map(|val| { .map(|val| {
val.map_or(false, |v| { val.map_or(false, |v| {
match v { match *v {
Value::String(s) => { Value::String(ref s) => {
match Version::parse(&s[..]) { match Version::parse(&s[..]) {
Ok(v) => v < self.version, Ok(v) => v < self.version,
_ => false _ => false

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -33,10 +34,10 @@
)] )]
extern crate filters; extern crate filters;
extern crate itertools;
extern crate regex; extern crate regex;
extern crate semver; extern crate semver;
extern crate toml; extern crate toml;
extern crate toml_query;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagentrytag; extern crate libimagentrytag;

View file

@ -17,11 +17,11 @@ homepage = "http://imag-pim.org"
itertools = "0.5" itertools = "0.5"
log = "0.3" log = "0.3"
toml = "^0.4" toml = "^0.4"
semver = "0.5"
url = "1.2" url = "1.2"
rust-crypto = "0.2" rust-crypto = "0.2"
env_logger = "0.3" env_logger = "0.3"
is-match = "0.1" is-match = "0.1"
toml-query = "0.3.0"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }

View file

@ -38,10 +38,12 @@ use libimagstore::store::Entry;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::IntoStoreId;
use libimagstore::toml_ext::TomlValueExt;
use libimagutil::debug_result::*; use libimagutil::debug_result::*;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use error::LinkError as LE; use error::LinkError as LE;
use error::LinkErrorKind as LEK; use error::LinkErrorKind as LEK;
use error::MapErrInto; use error::MapErrInto;
@ -71,7 +73,7 @@ impl Link for Entry {
.read("imag.content.url") .read("imag.content.url")
.map_err_into(LEK::EntryHeaderReadError) .map_err_into(LEK::EntryHeaderReadError)
.and_then(|opt| match opt { .and_then(|opt| match opt {
Some(Value::String(s)) => { Some(&Value::String(ref s)) => {
debug!("Found url, parsing: {:?}", s); debug!("Found url, parsing: {:?}", s);
Url::parse(&s[..]).map_err_into(LEK::InvalidUri).map(Some) Url::parse(&s[..]).map_err_into(LEK::InvalidUri).map(Some)
}, },
@ -82,7 +84,7 @@ impl Link for Entry {
fn get_url(&self) -> Result<Option<Url>> { fn get_url(&self) -> Result<Option<Url>> {
match self.get_header().read("imag.content.url") { match self.get_header().read("imag.content.url") {
Ok(Some(Value::String(s))) => { Ok(Some(&Value::String(ref s))) => {
Url::parse(&s[..]) Url::parse(&s[..])
.map(Some) .map(Some)
.map_err(|e| LE::new(LEK::EntryHeaderReadError, Some(Box::new(e)))) .map_err(|e| LE::new(LEK::EntryHeaderReadError, Some(Box::new(e))))
@ -347,10 +349,10 @@ impl ExternalLinker for Entry {
debug!("Generating header content!"); 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") { let mut table = match hdr.read("imag.content") {
Ok(Some(Value::Table(table))) => table, Ok(Some(&Value::Table(ref table))) => table.clone(),
Ok(Some(_)) => { Ok(Some(_)) => {
warn!("There is a value at 'imag.content' which is not a table."); warn!("There is a value at 'imag.content' which is not a table.");
warn!("Going to override this value"); warn!("Going to override this value");

View file

@ -25,9 +25,11 @@ use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::IntoStoreId;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagstore::store::Result as StoreResult; use libimagstore::store::Result as StoreResult;
use libimagstore::toml_ext::TomlValueExt;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use error::LinkErrorKind as LEK; use error::LinkErrorKind as LEK;
use error::MapErrInto; use error::MapErrInto;
use result::Result; use result::Result;
@ -388,7 +390,12 @@ pub mod iter {
impl InternalLinker for Entry { impl InternalLinker for Entry {
fn get_internal_links(&self) -> Result<LinkIter> { fn get_internal_links(&self) -> Result<LinkIter> {
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. /// 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<()> { fn add_internal_link(&mut self, link: &mut Entry) -> Result<()> {
@ -485,7 +496,9 @@ fn rewrite_links<I: Iterator<Item = Link>>(header: &mut Value, links: I) -> Resu
})); }));
debug!("Setting new link array: {:?}", links); 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(|_| ()) 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); 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<Option<Value>>) -> Result<LinkIter> { fn process_rw_result(links: Result<Option<Value>>) -> Result<LinkIter> {
use std::path::PathBuf; use std::path::PathBuf;
let links = match links { let links = match links {

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -26,6 +27,7 @@
unused_allocation, unused_allocation,
unused_import_braces, unused_import_braces,
unused_imports, unused_imports,
unused_must_use,
unused_mut, unused_mut,
unused_qualifications, unused_qualifications,
while_true, while_true,
@ -34,7 +36,7 @@
extern crate itertools; extern crate itertools;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate toml; extern crate toml;
extern crate semver; extern crate toml_query;
extern crate url; extern crate url;
extern crate crypto; extern crate crypto;
#[macro_use] extern crate is_match; #[macro_use] extern crate is_match;

View file

@ -16,7 +16,6 @@ homepage = "http://imag-pim.org"
[dependencies] [dependencies]
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
toml = "^0.4"
prettytable-rs = "0.6.*" prettytable-rs = "0.6.*"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }

View file

@ -35,7 +35,6 @@
extern crate clap; extern crate clap;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate toml;
extern crate prettytable; extern crate prettytable;
extern crate libimagstore; extern crate libimagstore;

View file

@ -16,7 +16,6 @@ homepage = "http://imag-pim.org"
[dependencies] [dependencies]
log = "0.3" log = "0.3"
hoedown = "5.0.0" hoedown = "5.0.0"
crossbeam = "0.2"
url = "1.2" url = "1.2"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -26,12 +27,12 @@
unused_allocation, unused_allocation,
unused_import_braces, unused_import_braces,
unused_imports, unused_imports,
unused_must_use,
unused_mut, unused_mut,
unused_qualifications, unused_qualifications,
while_true, while_true,
)] )]
extern crate crossbeam;
extern crate hoedown; extern crate hoedown;
extern crate url; extern crate url;
extern crate libimagstore; extern crate libimagstore;

View file

@ -17,13 +17,10 @@ homepage = "http://imag-pim.org"
itertools = "0.5" itertools = "0.5"
log = "0.3" log = "0.3"
rust-crypto = "0.2" rust-crypto = "0.2"
semver = "0.5"
toml = "^0.4" toml = "^0.4"
toml-query = "0.3.0" toml-query = "0.3.0"
version = "2.0.1"
walkdir = "1.0.*" walkdir = "1.0.*"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagentrylist = { version = "0.4.0", path = "../../../lib/entry/libimagentrylist" } libimagentrylist = { version = "0.4.0", path = "../../../lib/entry/libimagentrylist" }
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }

View file

@ -37,13 +37,13 @@ impl RefFlags {
/// It assumes that this is a Map with Key = <name of the setting> and Value = boolean. /// It assumes that this is a Map with Key = <name of the setting> and Value = boolean.
pub fn read(v: &Value) -> Result<RefFlags> { pub fn read(v: &Value) -> Result<RefFlags> {
fn get_field(v: &Value, key: &str) -> Result<bool> { fn get_field(v: &Value, key: &str) -> Result<bool> {
use libimagstore::toml_ext::TomlValueExt; use toml_query::read::TomlValueReadExt;
use error::MapErrInto; use error::MapErrInto;
v.read(key) v.read(key)
.map_err_into(REK::HeaderTomlError) .map_err_into(REK::HeaderTomlError)
.and_then(|toml| match toml { .and_then(|toml| match toml {
Some(Value::Boolean(b)) => Ok(b), Some(&Value::Boolean(b)) => Ok(b),
Some(_) => Err(REK::HeaderTypeError.into()), Some(_) => Err(REK::HeaderTypeError.into()),
None => Err(REK::HeaderFieldMissingError.into()), None => Err(REK::HeaderFieldMissingError.into()),
}) })

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -26,6 +27,7 @@
unused_allocation, unused_allocation,
unused_import_braces, unused_import_braces,
unused_imports, unused_imports,
unused_must_use,
unused_mut, unused_mut,
unused_qualifications, unused_qualifications,
while_true, while_true,
@ -34,15 +36,12 @@
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate crypto; extern crate crypto;
extern crate itertools; extern crate itertools;
extern crate semver;
extern crate toml; extern crate toml;
extern crate toml_query; extern crate toml_query;
extern crate version;
extern crate walkdir; extern crate walkdir;
#[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagerror;
extern crate libimagutil;
extern crate libimagentrylist; extern crate libimagentrylist;
module_entry_path_mod!("ref"); module_entry_path_mod!("ref");

View file

@ -25,10 +25,11 @@ use std::fs::File;
use std::fs::Permissions; use std::fs::Permissions;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagstore::toml_ext::TomlValueExt;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use error::RefErrorKind as REK; use error::RefErrorKind as REK;
use error::MapErrInto; use error::MapErrInto;
@ -140,7 +141,7 @@ impl Ref for Entry {
fn get_stored_hash_with_hasher<H: Hasher>(&self, h: &H) -> Result<String> { fn get_stored_hash_with_hasher<H: Hasher>(&self, h: &H) -> Result<String> {
match self.get_header().read(&format!("ref.content_hash.{}", h.hash_name())[..]) { match self.get_header().read(&format!("ref.content_hash.{}", h.hash_name())[..]) {
// content hash stored... // 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 // content hash header field has wrong type
Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()), Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()),
@ -208,7 +209,7 @@ impl Ref for Entry {
.map_err_into(REK::HeaderFieldReadError) .map_err_into(REK::HeaderFieldReadError)
.and_then(|ro| { .and_then(|ro| {
match ro { match ro {
Some(Value::Boolean(b)) => Ok(b), Some(&Value::Boolean(b)) => Ok(b),
Some(_) => Err(REK::HeaderTypeError.into_error()), Some(_) => Err(REK::HeaderTypeError.into_error()),
None => Err(REK::HeaderFieldMissingError.into_error()), None => Err(REK::HeaderFieldMissingError.into_error()),
} }
@ -254,7 +255,7 @@ impl Ref for Entry {
/// Get the path of the file which is reffered to by this Ref /// Get the path of the file which is reffered to by this Ref
fn fs_file(&self) -> Result<PathBuf> { fn fs_file(&self) -> Result<PathBuf> {
match self.get_header().read("ref.path") { match self.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(Some(_)) => Err(REK::HeaderTypeError.into_error()),
Ok(None) => Err(REK::HeaderFieldMissingError.into_error()), Ok(None) => Err(REK::HeaderFieldMissingError.into_error()),
Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))), Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))),

View file

@ -25,7 +25,6 @@ use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::IntoStoreId;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::toml_ext::TomlValueExt;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use toml::Value; use toml::Value;
@ -145,6 +144,8 @@ impl RefStore for Store {
fn create_with_hasher<'a, H: Hasher>(&'a self, pb: PathBuf, flags: RefFlags, mut h: H) fn create_with_hasher<'a, H: Hasher>(&'a self, pb: PathBuf, flags: RefFlags, mut h: H)
-> Result<FileLockEntry<'a>> -> Result<FileLockEntry<'a>>
{ {
use toml_query::insert::TomlValueInsertExt;
if !pb.exists() { if !pb.exists() {
return Err(REK::RefTargetDoesNotExist.into_error()); return Err(REK::RefTargetDoesNotExist.into_error());
} }
@ -244,10 +245,13 @@ impl RefStore for Store {
match tpl { match tpl {
&Some((ref s, ref v)) => { &Some((ref s, ref v)) => {
match fle.get_header_mut().insert(s, v.clone()) { match fle.get_header_mut().insert(s, v.clone()) {
Ok(false) => { Ok(Some(_)) => {
let e = REK::HeaderFieldAlreadyExistsError.into_error(); let e = REK::HeaderFieldAlreadyExistsError.into_error();
return Err(e).map_err_into(REK::HeaderFieldWriteError); return Err(e).map_err_into(REK::HeaderFieldWriteError);
}, },
Ok(None) => {
// Okay, we just inserted a new header value...
},
Err(e) => return Err(e).map_err_into(REK::HeaderFieldWriteError), Err(e) => return Err(e).map_err_into(REK::HeaderFieldWriteError),
_ => (), _ => (),
} }

View file

@ -21,7 +21,7 @@ toml = "^0.4"
itertools = "0.5" itertools = "0.5"
is-match = "0.1" is-match = "0.1"
filters = "0.1" filters = "0.1"
toml-query = "0.3.0"
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }

View file

@ -18,6 +18,7 @@
// //
#![deny( #![deny(
dead_code,
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
path_statements, path_statements,
@ -26,6 +27,7 @@
unused_allocation, unused_allocation,
unused_import_braces, unused_import_braces,
unused_imports, unused_imports,
unused_must_use,
unused_mut, unused_mut,
unused_qualifications, unused_qualifications,
while_true, while_true,
@ -36,12 +38,12 @@ extern crate itertools;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate regex; extern crate regex;
extern crate toml; extern crate toml;
extern crate toml_query;
#[macro_use] extern crate is_match; #[macro_use] extern crate is_match;
extern crate filters; extern crate filters;
extern crate libimagstore; extern crate libimagstore;
#[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagerror;
extern crate libimagutil;
pub mod error; pub mod error;
pub mod exec; pub mod exec;

View file

@ -21,7 +21,9 @@ use itertools::Itertools;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use libimagstore::toml_ext::TomlValueExt;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use error::TagErrorKind; use error::TagErrorKind;
use error::MapErrInto; use error::MapErrInto;
@ -50,7 +52,7 @@ impl Tagable for Value {
let tags = try!(self.read("imag.tags").map_err_into(TagErrorKind::HeaderReadError)); let tags = try!(self.read("imag.tags").map_err_into(TagErrorKind::HeaderReadError));
match tags { match tags {
Some(Value::Array(tags)) => { Some(&Value::Array(ref tags)) => {
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()); return Err(TagErrorKind::TagTypeError.into());
} }
@ -120,7 +122,7 @@ impl Tagable for Value {
fn has_tag(&self, t: TagSlice) -> Result<bool> { fn has_tag(&self, t: TagSlice) -> Result<bool> {
let tags = try!(self.read("imag.tags").map_err_into(TagErrorKind::HeaderReadError)); 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()); return Err(TagErrorKind::TagTypeError.into());
} }
@ -128,7 +130,7 @@ impl Tagable for Value {
.iter() .iter()
.any(|tag| { .any(|tag| {
match *tag { match *tag {
Value::String(ref s) => { s == t }, &Value::String(ref s) => { s == t },
_ => unreachable!() _ => unreachable!()
} }
})) }))

Some files were not shown because too many files have changed in this diff Show more