summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-02-06 21:45:37 +0100
committerGitHub <noreply@github.com>2018-02-06 21:45:37 +0100
commit1b588172dd61e0079f3fc39d3d996384316a41e0 (patch)
treec5936a53b7cf1ecfdfb51e63c3f4dec21440590c
parent8006edb806c44b23b5fbeab5ff828bb56cba8bc9 (diff)
parent29e88c5de0c9c8df9119a368406884caee7378ed (diff)
downloadimag-1b588172dd61e0079f3fc39d3d996384316a41e0.zip
imag-1b588172dd61e0079f3fc39d3d996384316a41e0.tar.gz
Merge pull request #1255 from matthiasbeyer/imag-notes/fix-list
Fix imag-notes list errors
-rw-r--r--bin/domain/imag-notes/Cargo.toml1
-rw-r--r--bin/domain/imag-notes/src/main.rs13
-rw-r--r--lib/domain/libimagnotes/src/error.rs4
-rw-r--r--lib/domain/libimagnotes/src/notestore.rs17
4 files changed, 19 insertions, 16 deletions
diff --git a/bin/domain/imag-notes/Cargo.toml b/bin/domain/imag-notes/Cargo.toml
index 2d77b65..9d4091e 100644
--- a/bin/domain/imag-notes/Cargo.toml
+++ b/bin/domain/imag-notes/Cargo.toml
@@ -29,3 +29,4 @@ libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror"
libimagnotes = { version = "0.6.0", path = "../../../lib/domain/libimagnotes" }
libimagentryedit = { version = "0.6.0", path = "../../../lib/entry/libimagentryedit" }
libimagutil = { version = "0.6.0", path = "../../../lib/etc/libimagutil" }
+libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
diff --git a/bin/domain/imag-notes/src/main.rs b/bin/domain/imag-notes/src/main.rs
index d04208e..35b38b0 100644
--- a/bin/domain/imag-notes/src/main.rs
+++ b/bin/domain/imag-notes/src/main.rs
@@ -26,15 +26,21 @@ extern crate libimagrt;
extern crate libimagentryedit;
extern crate libimagerror;
extern crate libimagutil;
+extern crate libimagstore;
+
+use std::process::exit;
use itertools::Itertools;
use libimagentryedit::edit::Edit;
use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup;
+use libimagstore::iter::get::StoreIdGetIteratorExtension;
use libimagnotes::note::Note;
use libimagnotes::notestore::*;
use libimagerror::trace::MapErrTrace;
+use libimagerror::trace::trace_error_exit;
+use libimagerror::iter::TraceIterator;
use libimagutil::info_result::*;
use libimagutil::warn_result::WarnResult;
@@ -114,7 +120,12 @@ fn list(rt: &Runtime) {
.store()
.all_notes()
.map_err_trace_exit_unwrap(1)
- .filter_map(|noteid| rt.store().get(noteid).map_err_trace_exit_unwrap(1))
+ .into_get_iter(rt.store())
+ .unwrap_with(|e| trace_error_exit(&e, 1))
+ .map(|opt| opt.unwrap_or_else(|| {
+ error!("Fatal: Nonexistent entry where entry should exist");
+ exit(1)
+ }))
.sorted_by(|note_a, note_b| if let (Ok(a), Ok(b)) = (note_a.get_name(), note_b.get_name()) {
return a.cmp(&b)
} else {
diff --git a/lib/domain/libimagnotes/src/error.rs b/lib/domain/libimagnotes/src/error.rs
index 6359edb..fad3151 100644
--- a/lib/domain/libimagnotes/src/error.rs
+++ b/lib/domain/libimagnotes/src/error.rs
@@ -22,6 +22,10 @@ error_chain! {
NoteError, NoteErrorKind, ResultExt, Result;
}
+ foreign_links {
+ TomlQueryError(::toml_query::error::Error);
+ }
+
errors {
StoreWriteError {
description("Error writing store")
diff --git a/lib/domain/libimagnotes/src/notestore.rs b/lib/domain/libimagnotes/src/notestore.rs
index 0547b68..2df2235 100644
--- a/lib/domain/libimagnotes/src/notestore.rs
+++ b/lib/domain/libimagnotes/src/notestore.rs
@@ -17,15 +17,13 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
-use std::collections::BTreeMap;
-
use toml::Value;
use libimagstore::storeid::IntoStoreId;
use libimagstore::store::FileLockEntry;
use libimagstore::store::Store;
-use toml_query::set::TomlValueSetExt;
+use toml_query::insert::TomlValueInsertExt;
use module_path::ModuleEntryPath;
use error::Result;
@@ -56,18 +54,7 @@ impl<'a> NoteStore<'a> for Store {
{
let entry = lockentry.deref_mut();
-
- {
- let header = entry.get_header_mut();
- let _ = header
- .set("note", Value::Table(BTreeMap::new()))
- .chain_err(|| NEK::StoreWriteError);
-
- let _ = header
- .set("note.name", Value::String(name))
- .chain_err(|| NEK::StoreWriteError);
- }
-
+ entry.get_header_mut().insert("note.name", Value::String(name))?;
*entry.get_content_mut() = text;
}