From 3c1f9fa15f745a8acecfef3f9f96211cdafb89ec Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 14 Apr 2016 17:22:47 +0200 Subject: [PATCH 01/38] Move test utilities to top-level test directory --- imag-store/tests/001-create_test.sh | 1 + imag-store/tests/002-retrieve_test.sh | 1 + imag-store/tests/003-delete_test.sh | 1 + imag-store/tests/utils.sh | 63 +--------------------- tests/utils.sh | 75 +++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 61 deletions(-) create mode 100644 tests/utils.sh diff --git a/imag-store/tests/001-create_test.sh b/imag-store/tests/001-create_test.sh index 91720c9f..823d8488 100644 --- a/imag-store/tests/001-create_test.sh +++ b/imag-store/tests/001-create_test.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh test_call() { diff --git a/imag-store/tests/002-retrieve_test.sh b/imag-store/tests/002-retrieve_test.sh index 33b96780..4e2c7d7c 100644 --- a/imag-store/tests/002-retrieve_test.sh +++ b/imag-store/tests/002-retrieve_test.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh std_header() { diff --git a/imag-store/tests/003-delete_test.sh b/imag-store/tests/003-delete_test.sh index 794f1ad8..9beaba82 100644 --- a/imag-store/tests/003-delete_test.sh +++ b/imag-store/tests/003-delete_test.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh create() { diff --git a/imag-store/tests/utils.sh b/imag-store/tests/utils.sh index 148eaf87..adf6cd88 100644 --- a/imag-store/tests/utils.sh +++ b/imag-store/tests/utils.sh @@ -1,65 +1,6 @@ -#!/usr/bin/env bash - -COLOR_OFF='\e[0m' # Text Reset -RED='\e[0;31m' # Red -YELLOW='\e[0;33m' # Yellow -GREEN='\e[0;32m' # Green - -RUNTIME="/tmp" -STORE="${RUNTIME}/store" - -out() { - [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${YELLOW}:: $*${COLOR_OFF}" -} - -success() { - [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${GREEN}>> $*${COLOR_OFF}" -} - -err() { - [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${RED}!! $*${COLOR_OFF}" -} - -silent() { - DEBUG_OUTPUT_OFF=1 $* -} +source $(dirname ${BASH_SOURCE[0]})/../tests/utils.sh imag-store() { - local searchdir=$(dirname ${BASH_SOURCE[0]})/../target/debug/ - [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; } - local bin=$(find $searchdir -iname imag-store -type f -executable) - local flags="--debug --rtp $RUNTIME" - out "Calling '$bin $flags $*'" - $bin $flags $* -} - -reset_store() { - rm -r "${STORE}" -} - -call_test() { - out "-- TESTING: '$1' --" - $1 - result=$? - if [[ -z "$DONT_RESET_STORE" ]]; then - out "Reseting store" - reset_store - out "Store reset done" - fi - [[ $result -eq 0 ]] || { err "-- FAILED: '$1'. Exiting."; exit 1; } - success "-- SUCCESS: '$1' --" -} - -invoke_tests() { - out "Invoking tests." - if [[ ! -z "$INVOKE_TEST" ]]; then - out "Invoking only $INVOKE_TEST" - call_test "$INVOKE_TEST" - else - out "Invoking $*" - for t in $*; do - call_test "$t" - done - fi + imag-call-binary "$(dirname ${BASH_SOURCE[0]})/../target/debug/" imag-store $* } diff --git a/tests/utils.sh b/tests/utils.sh new file mode 100644 index 00000000..8babfd21 --- /dev/null +++ b/tests/utils.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +# +# +# This file contains test utility functions which are used by the test scripts +# for each binary. +# +# + + +COLOR_OFF='\e[0m' # Text Reset +RED='\e[0;31m' # Red +YELLOW='\e[0;33m' # Yellow +GREEN='\e[0;32m' # Green + +RUNTIME="/tmp" +STORE="${RUNTIME}/store" + +out() { + [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${YELLOW}:: $*${COLOR_OFF}" +} + +success() { + [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${GREEN}>> $*${COLOR_OFF}" +} + +err() { + [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${RED}!! $*${COLOR_OFF}" +} + +silent() { + DEBUG_OUTPUT_OFF=1 $* +} + +imag-call-binary() { + local searchdir=$1; shift + local binary=$1; shift + [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; } + local bin=$(find $searchdir -iname $binary -type f -executable) + local flags="--debug --rtp $RUNTIME" + out "Calling '$bin $flags $*'" + $bin $flags $* +} + +reset_store() { + rm -r "${STORE}" +} + +call_test() { + out "-- TESTING: '$1' --" + $1 + result=$? + if [[ -z "$DONT_RESET_STORE" ]]; then + out "Reseting store" + reset_store + out "Store reset done" + fi + [[ $result -eq 0 ]] || { err "-- FAILED: '$1'. Exiting."; exit 1; } + success "-- SUCCESS: '$1' --" +} + +invoke_tests() { + out "Invoking tests." + if [[ ! -z "$INVOKE_TEST" ]]; then + out "Invoking only $INVOKE_TEST" + call_test "$INVOKE_TEST" + else + out "Invoking $*" + for t in $*; do + call_test "$t" + done + fi +} + + From 91be10cb9788c69451cad1bd1a9c9156aee87a26 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 14 Apr 2016 17:38:58 +0200 Subject: [PATCH 02/38] Add link-test utilities --- imag-link/tests/utils.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 imag-link/tests/utils.sh diff --git a/imag-link/tests/utils.sh b/imag-link/tests/utils.sh new file mode 100644 index 00000000..ff9e9975 --- /dev/null +++ b/imag-link/tests/utils.sh @@ -0,0 +1,6 @@ +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh + +imag-link() { + imag-call-binary "$(dirname ${BASH_SOURCE[0]})/../target/debug/" imag-link $* +} + From 8b7f6d2e8e26d8cc5875fcd84e75af8b62460012 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 14 Apr 2016 17:39:05 +0200 Subject: [PATCH 03/38] Add link-test testing --- imag-link/tests/link-test.sh | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 imag-link/tests/link-test.sh diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh new file mode 100644 index 00000000..362b0292 --- /dev/null +++ b/imag-link/tests/link-test.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh +source $(dirname ${BASH_SOURCE[0]})/utils.sh + +default_entry() { + cat < ${STORE}/$1 +} + +test_link_modificates() { + mktestentry "test~0.1.0" + mktestentry "test2~0.1.0" + + imag-link --from "test~0.1.0" --to "test2~0.1.0" + + if [[ "$(default_entry)" -eq "$(cat_entry 'test~0.1.0')" ]] || + [[ "$(default_entry)" -eq "$(cat_entry 'test2~0.1.0')" ]] + then + err "Entry was unmodified after linking" + return 1; + fi +} + +invoke_tests \ + test_link_modificates + From 4cee962a0621095346a4db7cc9189dc7f59fd6e1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Apr 2016 16:24:38 +0200 Subject: [PATCH 04/38] Quote test script name for easier debugging --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d8b05f08..89211edd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ script: } run_sh_test() { - echo "--- Running test script: $1" + echo "--- Running test script: '$1'" bash $1 || { echo "--- Test failed. Exiting"; exit 1; } echo "--- Test script $1 executed successfully" } From e117fdaa70f70b7d31de20b7de4b8bbf987a122f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Apr 2016 18:32:13 +0200 Subject: [PATCH 05/38] Add helper function to cat an entry from the store --- tests/utils.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/utils.sh b/tests/utils.sh index 8babfd21..6fc23ad8 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -42,6 +42,10 @@ imag-call-binary() { $bin $flags $* } +cat_entry() { + cat ${STORE}/$1 +} + reset_store() { rm -r "${STORE}" } From 15fde996588b536d22b3b0b19973a15fe743259c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Apr 2016 22:55:39 +0200 Subject: [PATCH 06/38] Add test whether linking actually links --- imag-link/tests/link-test.sh | 37 +++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh index 362b0292..2caf8e99 100644 --- a/imag-link/tests/link-test.sh +++ b/imag-link/tests/link-test.sh @@ -14,6 +14,17 @@ version = "0.1.0" EOS } +entry_linked_to() { + cat < ${STORE}/$1 @@ -23,7 +34,7 @@ test_link_modificates() { mktestentry "test~0.1.0" mktestentry "test2~0.1.0" - imag-link --from "test~0.1.0" --to "test2~0.1.0" + imag-link internal add --from "test~0.1.0" --to "test2~0.1.0" if [[ "$(default_entry)" -eq "$(cat_entry 'test~0.1.0')" ]] || [[ "$(default_entry)" -eq "$(cat_entry 'test2~0.1.0')" ]] @@ -33,6 +44,26 @@ test_link_modificates() { fi } -invoke_tests \ - test_link_modificates +test_linking_links() { + mktestentry "test~0.1.0" + mktestentry "test2~0.1.0" + + imag-link internal add --from "test~0.1.0" --to "test2~0.1.0" + + if [[ "$(entry_linked_to '/test~0.1.0')" == "$(cat_entry 'test2~0.1.0')" ]]; + then + err "Linking to 'test~0.1.0' didn't succeed for 'test2~0.1.0'" + err $(cat_entry 'test2~0.1.0') + fi + + if [[ "$(entry_linked_to '/test2~0.1.0')" == "$(cat_entry 'test~0.1.0')" ]]; + then + err "Linking to 'test2~0.1.0' didn't succeed for 'test~0.1.0'" + err $(cat_entry 'test~0.1.0') + fi +} + +invoke_tests \ + test_link_modificates \ + test_linking_links From ad18fdd60434f7388ec44c0ecb49f8b555d3ea81 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:05:34 +0200 Subject: [PATCH 07/38] imag-link: Replace .err().unwrap() with .unwrap_err() --- imag-link/src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imag-link/src/main.rs b/imag-link/src/main.rs index d20bbac3..70f1d019 100644 --- a/imag-link/src/main.rs +++ b/imag-link/src/main.rs @@ -53,7 +53,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; @@ -200,7 +200,7 @@ fn handle_external_linking(rt: &Runtime) { let entry_name = scmd.value_of("id").unwrap(); // enforced by clap let entry = get_entry_by_name(rt, entry_name); if entry.is_err() { - trace_error(&entry.err().unwrap()); + trace_error(&entry.unwrap_err()); exit(1); } let mut entry = entry.unwrap(); @@ -238,7 +238,7 @@ fn add_link_to_entry(store: &Store, matches: &ArgMatches, entry: &mut FileLockEn let link = Url::parse(link); if link.is_err() { debug!("URL parsing error..."); - trace_error(&link.err().unwrap()); + trace_error(&link.unwrap_err()); debug!("Exiting"); exit(1); } @@ -258,7 +258,7 @@ fn remove_link_from_entry(store: &Store, matches: &ArgMatches, entry: &mut FileL let link = Url::parse(link); if link.is_err() { - trace_error(&link.err().unwrap()); + trace_error(&link.unwrap_err()); exit(1); } let link = link.unwrap(); From da3b463ff007b78921fa0e78d2ed3eab8255f1e8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:07:14 +0200 Subject: [PATCH 08/38] imag-counter: Replace .err().unwrap() with .unwrap_err() --- imag-counter/src/list.rs | 4 ++-- imag-counter/src/main.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/imag-counter/src/list.rs b/imag-counter/src/list.rs index 2d1c80bb..b7276957 100644 --- a/imag-counter/src/list.rs +++ b/imag-counter/src/list.rs @@ -15,11 +15,11 @@ pub fn list(rt: &Runtime) { let value = c.value(); if name.is_err() { - trace_error(&name.err().unwrap()); + trace_error(&name.unwrap_err()); } else { if value.is_err() { - trace_error(&value.err().unwrap()); + trace_error(&value.unwrap_err()); } else { println!("{} - {}", name.unwrap(), value.unwrap()); } diff --git a/imag-counter/src/main.rs b/imag-counter/src/main.rs index 964556e3..538149dc 100644 --- a/imag-counter/src/main.rs +++ b/imag-counter/src/main.rs @@ -59,7 +59,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; From 85800e77587e393155adb25234091306fbe0b618 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:07:31 +0200 Subject: [PATCH 09/38] imag-notes: Replace .err().unwrap() with .unwrap_err() --- imag-notes/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imag-notes/src/main.rs b/imag-notes/src/main.rs index 1c6dedfb..bea757fa 100644 --- a/imag-notes/src/main.rs +++ b/imag-notes/src/main.rs @@ -29,7 +29,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; @@ -81,7 +81,7 @@ fn edit(rt: &Runtime) { fn edit_entry(rt: &Runtime, name: String) -> bool { let note = Note::retrieve(rt.store(), name); if note.is_err() { - trace_error(¬e.err().unwrap()); + trace_error(¬e.unwrap_err()); warn!("Cannot edit nonexistent Note"); return false } @@ -100,7 +100,7 @@ fn list(rt: &Runtime) { let iter = Note::all_notes(rt.store()); if iter.is_err() { - trace_error(&iter.err().unwrap()); + trace_error(&iter.unwrap_err()); exit(1); } From cd73be256b22404c342bad782c2e1453f3e5f526 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:07:39 +0200 Subject: [PATCH 10/38] imag-store: Replace .err().unwrap() with .unwrap_err() --- imag-store/src/create.rs | 2 +- imag-store/src/delete.rs | 2 +- imag-store/src/main.rs | 2 +- imag-store/src/retrieve.rs | 2 +- imag-store/src/update.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/imag-store/src/create.rs b/imag-store/src/create.rs index 9d90f642..35ac162a 100644 --- a/imag-store/src/create.rs +++ b/imag-store/src/create.rs @@ -38,7 +38,7 @@ pub fn create(rt: &Runtime) { let path = build_entry_path(rt.store(), path.unwrap()); if path.is_err() { - trace_error(&path.err().unwrap()); + trace_error(&path.unwrap_err()); exit(1); } let path = path.unwrap(); diff --git a/imag-store/src/delete.rs b/imag-store/src/delete.rs index 71bf0f91..f232ec0a 100644 --- a/imag-store/src/delete.rs +++ b/imag-store/src/delete.rs @@ -14,7 +14,7 @@ pub fn delete(rt: &Runtime) { .map(|id| { let path = build_entry_path(rt.store(), id); if path.is_err() { - trace_error(&path.err().unwrap()); + trace_error(&path.unwrap_err()); exit(1); } let path = path.unwrap(); diff --git a/imag-store/src/main.rs b/imag-store/src/main.rs index 4b5968d7..034e2b15 100644 --- a/imag-store/src/main.rs +++ b/imag-store/src/main.rs @@ -36,7 +36,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs index cc43ece2..8fbeeda3 100644 --- a/imag-store/src/retrieve.rs +++ b/imag-store/src/retrieve.rs @@ -19,7 +19,7 @@ pub fn retrieve(rt: &Runtime) { .map(|id| { let path = build_entry_path(rt.store(), id); if path.is_err() { - trace_error(&path.err().unwrap()); + trace_error(&path.unwrap_err()); exit(1); } let path = path.unwrap(); diff --git a/imag-store/src/update.rs b/imag-store/src/update.rs index d37da1c2..0e054106 100644 --- a/imag-store/src/update.rs +++ b/imag-store/src/update.rs @@ -16,7 +16,7 @@ pub fn update(rt: &Runtime) { .map(|id| { let path = build_entry_path(rt.store(), id); if path.is_err() { - trace_error(&path.err().unwrap()); + trace_error(&path.unwrap_err()); exit(1); } let path = path.unwrap(); From c8e5ea49ce05293268a586f082c2e5c4ee50bdde Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:07:47 +0200 Subject: [PATCH 11/38] imag-tag: Replace .err().unwrap() with .unwrap_err() --- imag-tag/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imag-tag/src/main.rs b/imag-tag/src/main.rs index 2b6201dc..e1a35a34 100644 --- a/imag-tag/src/main.rs +++ b/imag-tag/src/main.rs @@ -32,7 +32,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; @@ -127,7 +127,7 @@ fn list(id: &str, rt: &Runtime) { if entry.is_err() { debug!("Could not retrieve '{:?}' => {:?}", id, path); warn!("Could not retrieve entry '{}'", id); - trace_error(&entry.err().unwrap()); + trace_error(&entry.unwrap_err()); exit(1); } let entry = entry.unwrap(); @@ -146,7 +146,7 @@ fn list(id: &str, rt: &Runtime) { let tags = entry.get_tags(); if tags.is_err() { - trace_error(&tags.err().unwrap()); + trace_error(&tags.unwrap_err()); exit(1); } let tags = tags.unwrap(); From c1b4ce55b5d1a68bd0183261b47cb092c0af8671 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:07:57 +0200 Subject: [PATCH 12/38] imag-view: Replace .err().unwrap() with .unwrap_err() --- imag-view/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imag-view/src/main.rs b/imag-view/src/main.rs index 1f18ca17..f12e639d 100644 --- a/imag-view/src/main.rs +++ b/imag-view/src/main.rs @@ -54,7 +54,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); // we can afford not-executing destructors here } }; @@ -102,7 +102,7 @@ fn main() { let entry = load_entry(entry_id, entry_version, &rt); if entry.is_err() { - trace_error(&entry.err().unwrap()); + trace_error(&entry.unwrap_err()); exit(1); // we can afford not-executing destructors here } let entry = entry.unwrap(); From d01c2d294ec3b3a7afad40499e432f7c9cab2519 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:08:05 +0200 Subject: [PATCH 13/38] libimagcounter: Replace .err().unwrap() with .unwrap_err() --- libimagcounter/src/counter.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libimagcounter/src/counter.rs b/libimagcounter/src/counter.rs index bea7537e..c245e261 100644 --- a/libimagcounter/src/counter.rs +++ b/libimagcounter/src/counter.rs @@ -30,7 +30,7 @@ impl<'a> Counter<'a> { let fle = { let lockentry = store.create(ModuleEntryPath::new(name.clone()).into_storeid()); if lockentry.is_err() { - return Err(CE::new(CEK::StoreWriteError, Some(Box::new(lockentry.err().unwrap())))); + return Err(CE::new(CEK::StoreWriteError, Some(Box::new(lockentry.unwrap_err())))); } let mut lockentry = lockentry.unwrap(); @@ -39,17 +39,17 @@ impl<'a> Counter<'a> { let mut header = entry.get_header_mut(); let setres = header.set("counter", Value::Table(BTreeMap::new())); if setres.is_err() { - return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.err().unwrap())))); + return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.unwrap_err())))); } let setres = header.set("counter.name", Value::String(name)); if setres.is_err() { - return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.err().unwrap())))); + return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.unwrap_err())))); } let setres = header.set("counter.value", Value::Integer(init)); if setres.is_err() { - return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.err().unwrap())))); + return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.unwrap_err())))); } } From 5d2950b7df890094343da69d5dfab145e63c91a7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:08:16 +0200 Subject: [PATCH 14/38] libimagentrylink: Replace .err().unwrap() with .unwrap_err() --- libimagentrylink/src/external.rs | 2 +- libimagentrylink/src/internal.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libimagentrylink/src/external.rs b/libimagentrylink/src/external.rs index 9df53cca..6adb8a80 100644 --- a/libimagentrylink/src/external.rs +++ b/libimagentrylink/src/external.rs @@ -173,7 +173,7 @@ impl ExternalLinker for Entry { let file = store.retrieve(file_id.clone()); if file.is_err() { debug!("Failed to create or retrieve an file for this link '{:?}'", link); - return Err(LE::new(LEK::StoreWriteError, Some(Box::new(file.err().unwrap())))); + return Err(LE::new(LEK::StoreWriteError, Some(Box::new(file.unwrap_err())))); } let mut file = file.unwrap(); diff --git a/libimagentrylink/src/internal.rs b/libimagentrylink/src/internal.rs index e22214d1..a410349a 100644 --- a/libimagentrylink/src/internal.rs +++ b/libimagentrylink/src/internal.rs @@ -139,7 +139,7 @@ fn process_rw_result(links: StoreResult>) -> Result> { if links.is_err() { debug!("RW action on store failed. Generating LinkError"); let lerr = LinkError::new(LinkErrorKind::EntryHeaderReadError, - Some(Box::new(links.err().unwrap()))); + Some(Box::new(links.unwrap_err()))); return Err(lerr); } let links = links.unwrap(); From e08986842c5a1602adde82d8f9eecd948e7c4975 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:08:27 +0200 Subject: [PATCH 15/38] libimagentrytag: Replace .err().unwrap() with .unwrap_err() --- libimagentrytag/src/tagable.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libimagentrytag/src/tagable.rs b/libimagentrytag/src/tagable.rs index bd478a97..4dbe4efb 100644 --- a/libimagentrytag/src/tagable.rs +++ b/libimagentrytag/src/tagable.rs @@ -31,7 +31,7 @@ impl Tagable for EntryHeader { let tags = self.read("imag.tags"); if tags.is_err() { let kind = TagErrorKind::HeaderReadError; - return Err(TagError::new(kind, Some(Box::new(tags.err().unwrap())))); + return Err(TagError::new(kind, Some(Box::new(tags.unwrap_err())))); } let tags = tags.unwrap(); @@ -106,7 +106,7 @@ impl Tagable for EntryHeader { let tags = self.read("imag.tags"); if tags.is_err() { let kind = TagErrorKind::HeaderReadError; - return Err(TagError::new(kind, Some(Box::new(tags.err().unwrap())))); + return Err(TagError::new(kind, Some(Box::new(tags.unwrap_err())))); } let tags = tags.unwrap(); @@ -129,7 +129,7 @@ impl Tagable for EntryHeader { for tag in tags { let check = self.has_tag(tag); if check.is_err() { - return Err(check.err().unwrap()); + return Err(check.unwrap_err()); } let check = check.unwrap(); From 9ada2d9c98b2bde10b7556f4a62b0cc40b2af329 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:08:37 +0200 Subject: [PATCH 16/38] libimagnotes: Replace .err().unwrap() with .unwrap_err() --- libimagnotes/src/note.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libimagnotes/src/note.rs b/libimagnotes/src/note.rs index 4f30b3c6..0487cb1c 100644 --- a/libimagnotes/src/note.rs +++ b/libimagnotes/src/note.rs @@ -32,7 +32,7 @@ impl<'a> Note<'a> { let fle = { let lockentry = store.create(ModuleEntryPath::new(name.clone()).into_storeid()); if lockentry.is_err() { - return Err(NE::new(NEK::StoreWriteError, Some(Box::new(lockentry.err().unwrap())))); + return Err(NE::new(NEK::StoreWriteError, Some(Box::new(lockentry.unwrap_err())))); } let mut lockentry = lockentry.unwrap(); @@ -44,13 +44,13 @@ impl<'a> Note<'a> { let setres = header.set("note", Value::Table(BTreeMap::new())); if setres.is_err() { let kind = NEK::StoreWriteError; - return Err(NE::new(kind, Some(Box::new(setres.err().unwrap())))); + return Err(NE::new(kind, Some(Box::new(setres.unwrap_err())))); } let setres = header.set("note.name", Value::String(name)); if setres.is_err() { let kind = NEK::StoreWriteError; - return Err(NE::new(kind, Some(Box::new(setres.err().unwrap())))); + return Err(NE::new(kind, Some(Box::new(setres.unwrap_err())))); } } From 3631817827c9f9051946cc82d7090183f3e88272 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:08:44 +0200 Subject: [PATCH 17/38] libimagrt: Replace .err().unwrap() with .unwrap_err() --- libimagrt/src/runtime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index b89bf5b4..794dc3d7 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -73,7 +73,7 @@ impl<'a> Runtime<'a> { let cfg = Configuration::new(&rtp); let cfg = if cfg.is_err() { - let e = cfg.err().unwrap(); + let e = cfg.unwrap_err(); if e.err_type() != ConfigErrorKind::NoConfigFileFound { let cause : Option> = Some(Box::new(e)); return Err(RuntimeError::new(RuntimeErrorKind::Instantiate, cause)); From 0bb40fca111e9e19703e86bb8636dc389ca598de Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Apr 2016 21:08:54 +0200 Subject: [PATCH 18/38] libimagstore: Replace .err().unwrap() with .unwrap_err() --- libimagstore/src/store.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index fe38518c..87221253 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -156,7 +156,7 @@ impl Store { if c.is_err() { debug!("Failed"); return Err(StoreError::new(StoreErrorKind::StorePathCreate, - Some(Box::new(c.err().unwrap())))); + Some(Box::new(c.unwrap_err())))); } } else { if location.is_file() { @@ -434,7 +434,7 @@ impl Store { if guard.is_err() { return Err(StoreError::new(StoreErrorKind::HookRegisterError, - Some(Box::new(guard.err().unwrap())))); + Some(Box::new(guard.unwrap_err())))); } let mut guard = guard.unwrap(); for mut aspect in guard.deref_mut() { @@ -764,7 +764,7 @@ impl EntryHeader { pub fn set_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result> { let tokens = EntryHeader::tokenize(spec, sep); if tokens.is_err() { // return parser error if any - return Err(tokens.err().unwrap()); + return Err(tokens.unwrap_err()); } let tokens = tokens.unwrap(); debug!("tokens = {:?}", tokens); @@ -779,7 +779,7 @@ impl EntryHeader { let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens let value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens if value.is_err() { - return Err(value.err().unwrap()); + return Err(value.unwrap_err()); } let mut value = value.unwrap(); debug!("walked value = {:?}", value); @@ -871,14 +871,14 @@ impl EntryHeader { pub fn read_with_sep(&self, spec: &str, splitchr: char) -> Result> { let tokens = EntryHeader::tokenize(spec, splitchr); if tokens.is_err() { // return parser error if any - return Err(tokens.err().unwrap()); + return Err(tokens.unwrap_err()); } let tokens = tokens.unwrap(); let mut header_clone = self.header.clone(); // we clone as READing is simpler this way let value = EntryHeader::walk_header(&mut header_clone, tokens); // walk N-1 tokens if value.is_err() { - let e = value.err().unwrap(); + let e = value.unwrap_err(); return match e.err_type() { // We cannot find the header key, as there is no path to it StoreErrorKind::HeaderKeyNotFound => Ok(None), @@ -891,7 +891,7 @@ impl EntryHeader { pub fn delete(&mut self, spec: &str) -> Result> { let tokens = EntryHeader::tokenize(spec, '.'); if tokens.is_err() { // return parser error if any - return Err(tokens.err().unwrap()); + return Err(tokens.unwrap_err()); } let tokens = tokens.unwrap(); @@ -905,7 +905,7 @@ impl EntryHeader { let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens let value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens if value.is_err() { - return Err(value.err().unwrap()); + return Err(value.unwrap_err()); } let mut value = value.unwrap(); debug!("walked value = {:?}", value); From 01c226f0ca201d12c740626fae52f1b27e99a369 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Apr 2016 09:08:47 +0200 Subject: [PATCH 19/38] Revert change to unwrap_err() here, trait bounds not fulfilled --- libimagstore/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 87221253..445af899 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -434,7 +434,7 @@ impl Store { if guard.is_err() { return Err(StoreError::new(StoreErrorKind::HookRegisterError, - Some(Box::new(guard.unwrap_err())))); + Some(Box::new(guard.err().unwrap())))); } let mut guard = guard.unwrap(); for mut aspect in guard.deref_mut() { From 381a9b3f5b2ba3b7857f110bdfa8d8a2d72fde42 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Apr 2016 10:54:50 +0200 Subject: [PATCH 20/38] Revert change to unwrap_err() here, trait bounds not fulfilled --- libimagcounter/src/counter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagcounter/src/counter.rs b/libimagcounter/src/counter.rs index c245e261..2285071f 100644 --- a/libimagcounter/src/counter.rs +++ b/libimagcounter/src/counter.rs @@ -30,7 +30,7 @@ impl<'a> Counter<'a> { let fle = { let lockentry = store.create(ModuleEntryPath::new(name.clone()).into_storeid()); if lockentry.is_err() { - return Err(CE::new(CEK::StoreWriteError, Some(Box::new(lockentry.unwrap_err())))); + return Err(CE::new(CEK::StoreWriteError, Some(Box::new(lockentry.err().unwrap())))); } let mut lockentry = lockentry.unwrap(); From e0876bb7512f10594d51f036d31f44275b158e80 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Apr 2016 14:02:57 +0200 Subject: [PATCH 21/38] Make libimagrt::runtime::Runtime derive Debug --- libimagrt/src/runtime.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index 794dc3d7..7319958f 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -17,6 +17,7 @@ use logger::ImagLogger; use libimagstore::store::Store; +#[derive(Debug)] pub struct Runtime<'a> { rtp: PathBuf, configuration: Option, From 872114d86f18d372df9c0addf3a1ae733c71cabe Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Apr 2016 14:52:21 +0200 Subject: [PATCH 22/38] FileLockEntry: Derive Debug --- libimagstore/src/store.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 445af899..c47299ee 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -537,6 +537,7 @@ impl Drop for Store { } /// A struct that allows you to borrow an Entry +#[derive(Debug)] pub struct FileLockEntry<'a> { store: &'a Store, entry: Entry, From 90b4e3cc62b89aef5257d409d817880f3e4febd9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Apr 2016 15:58:35 +0200 Subject: [PATCH 23/38] Add derive(Debug) for Note --- libimagnotes/src/note.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/libimagnotes/src/note.rs b/libimagnotes/src/note.rs index 0487cb1c..24975d35 100644 --- a/libimagnotes/src/note.rs +++ b/libimagnotes/src/note.rs @@ -19,6 +19,7 @@ use result::Result; use error::NoteError as NE; use error::NoteErrorKind as NEK; +#[derive(Debug)] pub struct Note<'a> { entry: FileLockEntry<'a>, } From b909fea45b63e346ba2eb5cd1d391edbd94a72bc Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Apr 2016 18:23:47 +0200 Subject: [PATCH 24/38] Derive Debug for NoteIterator --- libimagnotes/src/note.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/libimagnotes/src/note.rs b/libimagnotes/src/note.rs index 24975d35..b5cc7063 100644 --- a/libimagnotes/src/note.rs +++ b/libimagnotes/src/note.rs @@ -172,6 +172,7 @@ impl<'a> Deref for Note<'a> { } +#[derive(Debug)] pub struct NoteIterator<'a> { store: &'a Store, iditer: StoreIdIterator, From fd9dee7dea44e372105f712bd0ff2bbd3daf760c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Apr 2016 18:40:59 +0200 Subject: [PATCH 25/38] Implement Debug for StoreIdIterator --- libimagstore/src/storeid.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index 35c3c0f8..7c5940c1 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -1,6 +1,9 @@ use std::path::PathBuf; use glob::Paths; use semver::Version; +use std::fmt::{Debug, Formatter}; +use std::fmt::Error as FmtError; +use std::result::Result as RResult; use error::{StoreError, StoreErrorKind}; use store::Result; @@ -94,6 +97,14 @@ pub struct StoreIdIterator { paths: Paths, } +impl Debug for StoreIdIterator { + + fn fmt(&self, fmt: &mut Formatter) -> RResult<(), FmtError> { + write!(fmt, "StoreIdIterator") + } + +} + impl StoreIdIterator { pub fn new(paths: Paths) -> StoreIdIterator { From cb3683940e7f97a40f88d04b5816e816d8bae5eb Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:13:58 +0200 Subject: [PATCH 26/38] Remove unneeded module specifiers from Deref{,Mut} impls --- libimagstore/src/store.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index fe38518c..2801a230 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -553,7 +553,7 @@ impl<'a> FileLockEntry<'a, > { } } -impl<'a> ::std::ops::Deref for FileLockEntry<'a> { +impl<'a> Deref for FileLockEntry<'a> { type Target = Entry; fn deref(&self) -> &Self::Target { @@ -561,7 +561,7 @@ impl<'a> ::std::ops::Deref for FileLockEntry<'a> { } } -impl<'a> ::std::ops::DerefMut for FileLockEntry<'a> { +impl<'a> DerefMut for FileLockEntry<'a> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.entry } From 985d2737872adc2a465b4d4a549560c8f5052321 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:18:22 +0200 Subject: [PATCH 27/38] Remove unused deref() call --- libimagentrylist/src/listers/path.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libimagentrylist/src/listers/path.rs b/libimagentrylist/src/listers/path.rs index 285802e2..0f1deac5 100644 --- a/libimagentrylist/src/listers/path.rs +++ b/libimagentrylist/src/listers/path.rs @@ -1,6 +1,5 @@ use std::io::stdout; use std::io::Write; -use std::ops::Deref; use lister::Lister; use result::Result; @@ -28,7 +27,7 @@ impl Lister for PathLister { use error::ListErrorKind as LEK; entries.fold(Ok(()), |accu, entry| { - accu.and_then(|_| Ok(entry.deref().get_location().clone())) + accu.and_then(|_| Ok(entry.get_location().clone())) .and_then(|pb| { if self.absolute { pb.canonicalize().map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e)))) From 169d835e220c99220931c292c21b0c08746a6a74 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:19:01 +0200 Subject: [PATCH 28/38] Remove unused deref() call --- libimagentrylist/src/listers/core.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libimagentrylist/src/listers/core.rs b/libimagentrylist/src/listers/core.rs index e7c5bb84..8c7ccf72 100644 --- a/libimagentrylist/src/listers/core.rs +++ b/libimagentrylist/src/listers/core.rs @@ -1,6 +1,5 @@ use std::io::stdout; use std::io::Write; -use std::ops::Deref; use lister::Lister; use result::Result; @@ -30,7 +29,7 @@ impl<'a> Lister for CoreLister<'a> { entries.fold(Ok(()), |accu, entry| { accu.and_then(|_| { - write!(stdout(), "{:?}\n", (self.lister)(entry.deref())) + write!(stdout(), "{:?}\n", (self.lister)(&entry)) .map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e)))) }) }) From e0988c5f766aaeea865f893419cc91b9438bc354 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:19:37 +0200 Subject: [PATCH 29/38] Remove unneeded deref() call --- libimagentrylink/src/external.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libimagentrylink/src/external.rs b/libimagentrylink/src/external.rs index 9df53cca..8c1e5b01 100644 --- a/libimagentrylink/src/external.rs +++ b/libimagentrylink/src/external.rs @@ -11,7 +11,6 @@ /// This helps us greatly with deduplication of URLs. /// -use std::ops::Deref; use std::ops::DerefMut; use std::collections::BTreeMap; @@ -60,8 +59,7 @@ impl<'a> Link<'a> { /// Get a link Url object from a FileLockEntry, ignore errors. fn get_link_uri_from_filelockentry(file: &FileLockEntry<'a>) -> Option { - file.deref() - .get_header() + file.get_header() .read("imag.content.uri") .ok() .and_then(|opt| { @@ -74,7 +72,6 @@ impl<'a> Link<'a> { pub fn get_url(&self) -> Result> { let opt = self.link - .deref() .get_header() .read("imag.content.uri"); From 69a73f0a6720d4cd81cb108f4258f173ab68187d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:21:47 +0200 Subject: [PATCH 30/38] Remove unneeded calls to deref() and deref_mut() --- libimagnotes/src/note.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libimagnotes/src/note.rs b/libimagnotes/src/note.rs index 4f30b3c6..aa186ef2 100644 --- a/libimagnotes/src/note.rs +++ b/libimagnotes/src/note.rs @@ -64,14 +64,14 @@ impl<'a> Note<'a> { } pub fn set_name(&mut self, n: String) -> Result<()> { - let mut header = self.entry.deref_mut().get_header_mut(); + let mut header = self.entry.get_header_mut(); header.set("note.name", Value::String(n)) .map_err(|e| NE::new(NEK::StoreWriteError, Some(Box::new(e)))) .map(|_| ()) } pub fn get_name(&self) -> Result { - let header = self.entry.deref().get_header(); + let header = self.entry.get_header(); match header.read("note.name") { Ok(Some(Value::String(s))) => Ok(String::from(s)), Ok(_) => { @@ -83,11 +83,11 @@ impl<'a> Note<'a> { } pub fn set_text(&mut self, n: String) { - *self.entry.deref_mut().get_content_mut() = n + *self.entry.get_content_mut() = n } pub fn get_text(&self) -> &String { - self.entry.deref().get_content() + self.entry.get_content() } pub fn delete(store: &Store, name: String) -> Result<()> { @@ -120,27 +120,27 @@ impl<'a> Edit for Note<'a> { impl<'a> Tagable for Note<'a> { fn get_tags(&self) -> TagResult> { - self.entry.deref().get_tags() + self.entry.get_tags() } fn set_tags(&mut self, ts: Vec) -> TagResult<()> { - self.entry.deref_mut().set_tags(ts) + self.entry.set_tags(ts) } fn add_tag(&mut self, t: Tag) -> TagResult<()> { - self.entry.deref_mut().add_tag(t) + self.entry.add_tag(t) } fn remove_tag(&mut self, t: Tag) -> TagResult<()> { - self.entry.deref_mut().remove_tag(t) + self.entry.remove_tag(t) } fn has_tag(&self, t: &Tag) -> TagResult { - self.entry.deref().has_tag(t) + self.entry.has_tag(t) } fn has_tags(&self, ts: &Vec) -> TagResult { - self.entry.deref().has_tags(ts) + self.entry.has_tags(ts) } } From 523eef009d827bf0d6fbb163ece679ac4d780b04 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:23:01 +0200 Subject: [PATCH 31/38] Remove unneeded calls to deref() --- imag-store/src/retrieve.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs index cc43ece2..0ebcfa7f 100644 --- a/imag-store/src/retrieve.rs +++ b/imag-store/src/retrieve.rs @@ -41,7 +41,7 @@ pub fn retrieve(rt: &Runtime) { fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) { if do_print_raw(scmd) { debug!("Printing raw content..."); - println!("{}", e.deref().to_str()); + println!("{}", e.to_str()); } else if do_filter(scmd) { debug!("Filtering..."); warn!("Filtering via header specs is currently now supported."); @@ -49,7 +49,6 @@ fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) { unimplemented!() } else { debug!("Printing structured..."); - let entry = e.deref(); if do_print_header(scmd) { debug!("Printing header..."); if do_print_header_as_json(rt.cli()) { @@ -60,13 +59,13 @@ fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) { } else { debug!("Printing header as TOML..."); // We have to Value::Table() for Display - println!("{}", Value::Table(entry.get_header().clone().into())) + println!("{}", Value::Table(e.get_header().clone().into())) } } if do_print_content(scmd) { debug!("Printing content..."); - println!("{}", entry.get_content()); + println!("{}", e.get_content()); } } From 75fbcef4aadf1293195cf6dd1eea7672d2191c58 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:31:29 +0200 Subject: [PATCH 32/38] Use unused results --- imag-store/src/create.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/imag-store/src/create.rs b/imag-store/src/create.rs index 9d90f642..9921bb05 100644 --- a/imag-store/src/create.rs +++ b/imag-store/src/create.rs @@ -32,7 +32,7 @@ pub fn create(rt: &Runtime) { let path = scmd.value_of("path").or_else(|| scmd.value_of("id")); if path.is_none() { warn!("No ID / Path provided. Exiting now"); - write!(stderr(), "No ID / Path provided. Exiting now"); + write!(stderr(), "No ID / Path provided. Exiting now").ok(); exit(1); } @@ -101,14 +101,15 @@ fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Res debug!("Content with len = {}", content.len()); Entry::from_str(path.clone(), &content[..]) - .map(|mut new_e| { - rt.store() + .and_then(|new_e| { + let r = rt.store() .create(path.clone()) .map(|mut old_e| { *old_e.deref_mut() = new_e; }); debug!("Entry build"); + r }) .map_err(|serr| StoreError::new(StoreErrorKind::BackendError, Some(Box::new(serr)))) } @@ -144,7 +145,7 @@ fn string_from_raw_src(raw_src: &str) -> String { debug!("Read {:?} bytes", res); } else { debug!("Reading entry from file at {:?}", raw_src); - OpenOptions::new() + let _ = OpenOptions::new() .read(true) .write(false) .create(false) From 73c844ceb1ab531aae8622f9299cb46e4c6ab12b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:31:42 +0200 Subject: [PATCH 33/38] Remove unused imports --- imag-store/src/delete.rs | 2 -- imag-store/src/retrieve.rs | 2 -- imag-store/src/update.rs | 1 - imag-store/src/util.rs | 3 --- 4 files changed, 8 deletions(-) diff --git a/imag-store/src/delete.rs b/imag-store/src/delete.rs index 71bf0f91..5386903e 100644 --- a/imag-store/src/delete.rs +++ b/imag-store/src/delete.rs @@ -1,5 +1,3 @@ -use std::path::PathBuf; - use libimagstore::storeid::build_entry_path; use libimagrt::runtime::Runtime; use libimagutil::trace::trace_error; diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs index cc43ece2..0a49b164 100644 --- a/imag-store/src/retrieve.rs +++ b/imag-store/src/retrieve.rs @@ -1,6 +1,4 @@ -use std::path::PathBuf; use std::ops::Deref; -use std::fmt::Display; use std::process::exit; use clap::ArgMatches; diff --git a/imag-store/src/update.rs b/imag-store/src/update.rs index d37da1c2..287624c5 100644 --- a/imag-store/src/update.rs +++ b/imag-store/src/update.rs @@ -1,4 +1,3 @@ -use std::path::PathBuf; use std::ops::DerefMut; use std::process::exit; diff --git a/imag-store/src/util.rs b/imag-store/src/util.rs index 61832e3a..27c8a9a0 100644 --- a/imag-store/src/util.rs +++ b/imag-store/src/util.rs @@ -1,13 +1,10 @@ use std::collections::BTreeMap; -use std::path::PathBuf; use std::str::Split; use clap::ArgMatches; -use semver::Version; use toml::Value; use libimagstore::store::EntryHeader; -use libimagrt::runtime::Runtime; use libimagutil::key_value_split::IntoKeyValue; pub fn build_toml_header(matches: &ArgMatches, mut header: EntryHeader) -> EntryHeader { From 713151af79c89378dfd64b16d0784a5c91066c6c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:31:53 +0200 Subject: [PATCH 34/38] Remove unneeded keyword "mut" --- imag-store/src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imag-store/src/util.rs b/imag-store/src/util.rs index 27c8a9a0..f14d462b 100644 --- a/imag-store/src/util.rs +++ b/imag-store/src/util.rs @@ -7,7 +7,7 @@ use toml::Value; use libimagstore::store::EntryHeader; use libimagutil::key_value_split::IntoKeyValue; -pub fn build_toml_header(matches: &ArgMatches, mut header: EntryHeader) -> EntryHeader { +pub fn build_toml_header(matches: &ArgMatches, header: EntryHeader) -> EntryHeader { debug!("Building header from cli spec"); if let Some(headerspecs) = matches.values_of("header") { let mut main = header.into(); From bcc7554389fd6532561a9c714189f9872c30cd3d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 13:27:05 +0200 Subject: [PATCH 35/38] Enable lints --- imag-store/src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/imag-store/src/main.rs b/imag-store/src/main.rs index 4b5968d7..679390e3 100644 --- a/imag-store/src/main.rs +++ b/imag-store/src/main.rs @@ -1,3 +1,18 @@ +#![deny( + 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 clap; #[macro_use] extern crate log; extern crate semver; From 7aeb0c283309f03398ebb1f96189077a657ade0f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 15:57:33 +0200 Subject: [PATCH 36/38] Remove unused import --- imag-store/src/retrieve.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs index 01c54bad..c6b6adc8 100644 --- a/imag-store/src/retrieve.rs +++ b/imag-store/src/retrieve.rs @@ -1,4 +1,3 @@ -use std::ops::Deref; use std::process::exit; use clap::ArgMatches; From ad4e73399ff98b6f34bc68a40f2a4b19475cc833 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 21 Apr 2016 16:36:13 +0200 Subject: [PATCH 37/38] Make trace() output a bit nicer --- libimagutil/src/trace.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libimagutil/src/trace.rs b/libimagutil/src/trace.rs index f075f037..9f25cfda 100644 --- a/libimagutil/src/trace.rs +++ b/libimagutil/src/trace.rs @@ -55,7 +55,7 @@ fn print_trace_maxdepth(idx: u64, e: &Error, max: u64) -> Option<&Error> { } else { write!(stderr(), "\n").ok(); } - write!(stderr(), "Error {:>4} : {}", idx, e.description()).ok(); + write!(stderr(), "ERROR[{:>4}]: {}", idx, e.description()).ok(); e.cause() } @@ -65,7 +65,7 @@ fn count_error_causes(e: &Error) -> u64 { } fn print_trace_dbg(idx: u64, e: &Error) { - debug!("Error {:>4} : {}", idx, e.description()); + debug!("ERROR[{:>4}]: {}", idx, e.description()); if e.cause().is_some() { debug!(" -- caused by:"); print_trace_dbg(idx + 1, e.cause().unwrap()); From f6e59c355e1388c3b3f1e9e9bf43f6e40fb6270b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 22 Apr 2016 15:10:22 +0200 Subject: [PATCH 38/38] Remove "caused by" marker As we are in debug mode anyways, a developer using this should know by the trace number that the next line is the cause. As we use the debug!() macro here, this would be printed on a new line, which is rather distracting instead of helpful. Therefor this patch removes this line. --- libimagutil/src/trace.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/libimagutil/src/trace.rs b/libimagutil/src/trace.rs index 9f25cfda..5b22c84c 100644 --- a/libimagutil/src/trace.rs +++ b/libimagutil/src/trace.rs @@ -67,7 +67,6 @@ fn count_error_causes(e: &Error) -> u64 { fn print_trace_dbg(idx: u64, e: &Error) { debug!("ERROR[{:>4}]: {}", idx, e.description()); if e.cause().is_some() { - debug!(" -- caused by:"); print_trace_dbg(idx + 1, e.cause().unwrap()); } }