diff --git a/lib/core/libimagstore/src/storeid.rs b/lib/core/libimagstore/src/storeid.rs index f269c39b..56177ea5 100644 --- a/lib/core/libimagstore/src/storeid.rs +++ b/lib/core/libimagstore/src/storeid.rs @@ -212,7 +212,7 @@ impl<'a> Display for StoreIdWithBase<'a> { #[macro_export] macro_rules! module_entry_path_mod { ($name:expr) => ( - #[deny(missing_docs, + #[allow(missing_docs, missing_copy_implementations, trivial_casts, trivial_numeric_casts, unstable_features, @@ -223,34 +223,23 @@ macro_rules! module_entry_path_mod { use std::convert::AsRef; use std::path::Path; use std::path::PathBuf; - use $crate::storeid::StoreId; use failure::Fallible as Result; - /// A Struct giving you the ability to choose store entries assigned - /// to it. - /// - /// It is created through a call to `new`. - pub struct ModuleEntryPath(PathBuf); + pub fn new_id>(p: P) -> Result { - impl ModuleEntryPath { - /// Path has to be a valid UTF-8 string or this will panic! - pub fn new>(pa: P) -> ModuleEntryPath { - let mut path = PathBuf::new(); - path.push(format!("{}", $name)); - path.push(pa.as_ref().clone()); - let name = pa.as_ref().file_name().unwrap() - .to_str().unwrap(); - path.set_file_name(name); - ModuleEntryPath(path) - } + let path_str = p + .as_ref() + .to_str() + .ok_or_else(|| { + format_err!("File path is not valid UTF-8: {}", p.as_ref().display()) + })?; + + let id = format!("{}/{}", $name, path_str); + + StoreId::new(PathBuf::from(id)) } - impl $crate::storeid::IntoStoreId for ModuleEntryPath { - fn into_storeid(self) -> Result<$crate::storeid::StoreId> { - StoreId::new(self.0) - } - } } ) } @@ -351,20 +340,18 @@ impl<'a> StoreIdIteratorWithStore<'a> { #[cfg(test)] mod test { - use storeid::IntoStoreId; - module_entry_path_mod!("test"); #[test] fn test_correct_path() { - let p = module_path::ModuleEntryPath::new("test"); + let p = ::storeid::test::module_path::new_id("test"); - assert_eq!(p.into_storeid().unwrap().to_str().unwrap(), "test/test"); + assert_eq!(p.unwrap().to_str().unwrap(), "test/test"); } #[test] fn storeid_in_collection() { - let p = module_path::ModuleEntryPath::new("1/2/3/4/5/6/7/8/9/0").into_storeid().unwrap(); + let p = ::storeid::test::module_path::new_id("1/2/3/4/5/6/7/8/9/0").unwrap(); assert!(p.is_in_collection(&["test", "1"])); assert!(p.is_in_collection(&["test", "1", "2"])); diff --git a/lib/domain/libimagbookmark/src/collection.rs b/lib/domain/libimagbookmark/src/collection.rs index 853a7619..47f26401 100644 --- a/lib/domain/libimagbookmark/src/collection.rs +++ b/lib/domain/libimagbookmark/src/collection.rs @@ -28,12 +28,10 @@ use regex::Regex; use failure::Fallible as Result; use failure::Error; -use module_path::ModuleEntryPath; use libimagstore::store::Store; use libimagstore::store::Entry; use libimagstore::store::FileLockEntry; -use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; use libimagentrylink::external::ExternalLinker; use libimagentrylink::external::iter::UrlIter; @@ -53,22 +51,19 @@ pub trait BookmarkCollectionStore<'a> { impl<'a> BookmarkCollectionStore<'a> for Store { fn new(&'a self, name: &str) -> Result> { - ModuleEntryPath::new(name) - .into_storeid() + ::module_path::new_id(name) .and_then(|id| self.create(id).map_err(Error::from)) .map_err(Error::from) } fn get(&'a self, name: &str) -> Result>> { - ModuleEntryPath::new(name) - .into_storeid() + ::module_path::new_id(name) .and_then(|id| self.get(id).map_err(Error::from)) .map_err(Error::from) } fn delete(&'a self, name: &str) -> Result<()> { - ModuleEntryPath::new(name) - .into_storeid() + ::module_path::new_id(name) .and_then(|id| self.delete(id).map_err(Error::from)) .map_err(Error::from) } diff --git a/lib/domain/libimagbookmark/src/lib.rs b/lib/domain/libimagbookmark/src/lib.rs index c1dacef3..6072070c 100644 --- a/lib/domain/libimagbookmark/src/lib.rs +++ b/lib/domain/libimagbookmark/src/lib.rs @@ -39,7 +39,7 @@ extern crate url; extern crate regex; -extern crate failure; +#[macro_use] extern crate failure; #[macro_use] extern crate libimagstore; extern crate libimagerror; diff --git a/lib/domain/libimagcontact/src/store.rs b/lib/domain/libimagcontact/src/store.rs index aab35ab4..7c877832 100644 --- a/lib/domain/libimagcontact/src/store.rs +++ b/lib/domain/libimagcontact/src/store.rs @@ -27,7 +27,6 @@ use vobject::vcard::Vcard; use failure::Error; use failure::Fallible as Result; -use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; use libimagstore::iter::Entries; use libimagstore::store::Store; @@ -36,7 +35,6 @@ use libimagentryutil::isa::Is; use contact::IsContact; use deser::DeserVcard; -use module_path::ModuleEntryPath; use util; pub trait ContactStore<'a> { @@ -98,7 +96,7 @@ fn prepare_fetching_from_store(buf: &str) -> Result<(StoreId, Value)> { toml_from_str::(&serialized)? }; - let sid = ModuleEntryPath::new(uid.raw()).into_storeid()?; + let sid = ::module_path::new_id(uid.raw())?; Ok((sid, value)) } diff --git a/lib/domain/libimagdiary/src/diaryid.rs b/lib/domain/libimagdiary/src/diaryid.rs index fb846db2..2055099c 100644 --- a/lib/domain/libimagdiary/src/diaryid.rs +++ b/lib/domain/libimagdiary/src/diaryid.rs @@ -34,8 +34,6 @@ use failure::err_msg; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; -use module_path::ModuleEntryPath; - #[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)] pub struct DiaryId { name: String, @@ -150,8 +148,9 @@ impl DiaryId { impl IntoStoreId for DiaryId { fn into_storeid(self) -> Result { + use std::path::PathBuf; let s : String = self.into(); - ModuleEntryPath::new(s).into_storeid() + ::module_path::new_id(PathBuf::from(s)) } } diff --git a/lib/domain/libimagdiary/src/lib.rs b/lib/domain/libimagdiary/src/lib.rs index 7f0ce56e..bd03f3f0 100644 --- a/lib/domain/libimagdiary/src/lib.rs +++ b/lib/domain/libimagdiary/src/lib.rs @@ -42,7 +42,7 @@ extern crate chrono; extern crate toml; extern crate toml_query; extern crate itertools; -extern crate failure; +#[macro_use] extern crate failure; extern crate filters; #[macro_use] extern crate libimagstore; diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs index 188dcbb4..2fcc33fd 100644 --- a/lib/domain/libimaghabit/src/habit.rs +++ b/lib/domain/libimaghabit/src/habit.rs @@ -37,7 +37,6 @@ use libimagstore::store::Store; use libimagstore::store::FileLockEntry; use libimagstore::store::Entry; use libimagstore::storeid::StoreId; -use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreIdIterator; use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; @@ -258,11 +257,7 @@ impl HabitTemplate for Entry { } fn instance_id_for_name_and_datestr(habit_name: &String, habit_date: &String) -> Result { - use module_path::ModuleEntryPath; - - ModuleEntryPath::new(format!("instance/{}-{}", habit_name, habit_date)) - .into_storeid() - .map_err(Error::from) + ::module_path::new_id(format!("instance/{}-{}", habit_name, habit_date)).map_err(Error::from) } pub mod builder { @@ -272,7 +267,6 @@ pub mod builder { use libimagstore::store::Store; use libimagstore::storeid::StoreId; - use libimagstore::storeid::IntoStoreId; use libimagstore::store::FileLockEntry; use libimagentryutil::isa::Is; use libimagutil::debug_result::DebugResult; @@ -393,8 +387,7 @@ pub mod builder { /// Buld a StoreId for a Habit from a date object and a name of a habit fn build_habit_template_sid(name: &String) -> Result { - use module_path::ModuleEntryPath; - ModuleEntryPath::new(format!("template/{}", name)).into_storeid().map_err(From::from) + ::module_path::new_id(format!("template/{}", name)).map_err(From::from) } } diff --git a/lib/domain/libimagmail/src/store.rs b/lib/domain/libimagmail/src/store.rs index 6c672d9e..3355a2c9 100644 --- a/lib/domain/libimagmail/src/store.rs +++ b/lib/domain/libimagmail/src/store.rs @@ -27,7 +27,6 @@ use toml_query::insert::TomlValueInsertExt; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; -use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; use libimagstore::iter::Entries; use libimagentryref::hasher::default::DefaultHasher; @@ -36,7 +35,6 @@ use libimagentryref::reference::RefFassade; use libimagentryref::reference::Ref; use libimagentryref::reference::MutRef; -use module_path::ModuleEntryPath; use mid::MessageId; use mail::Mail; use hasher::MailHasher; @@ -69,7 +67,7 @@ impl<'a> MailStore<'a> for Store { CollName: AsRef + Debug { let message_id = get_message_id_for_mailfile(p.as_ref())?; - let new_sid = ModuleEntryPath::new(message_id.clone()).into_storeid()?; + let new_sid = ::module_path::new_id(message_id.clone())?; let mut entry = self.create(new_sid)?; let _ = entry @@ -90,7 +88,7 @@ impl<'a> MailStore<'a> for Store { where P: AsRef + Debug { let message_id = get_message_id_for_mailfile(p.as_ref())?; - let new_sid = ModuleEntryPath::new(message_id.clone()).into_storeid()?; + let new_sid = ::module_path::new_id(message_id.clone())?; match self.get(new_sid)? { Some(mut entry) => { @@ -117,7 +115,7 @@ impl<'a> MailStore<'a> for Store { CollName: AsRef + Debug { let message_id = get_message_id_for_mailfile(&p)?; - let new_sid = ModuleEntryPath::new(message_id.clone()).into_storeid()?; + let new_sid = ::module_path::new_id(message_id.clone())?; let mut entry = self.retrieve(new_sid)?; let _ = entry diff --git a/lib/domain/libimagnotes/src/lib.rs b/lib/domain/libimagnotes/src/lib.rs index 395c3cc8..81b5a42e 100644 --- a/lib/domain/libimagnotes/src/lib.rs +++ b/lib/domain/libimagnotes/src/lib.rs @@ -40,7 +40,7 @@ #[macro_use] extern crate log; extern crate toml; extern crate toml_query; -extern crate failure; +#[macro_use] extern crate failure; extern crate libimagrt; #[macro_use] extern crate libimagstore; diff --git a/lib/domain/libimagnotes/src/notestore.rs b/lib/domain/libimagnotes/src/notestore.rs index 87a26dea..4245bce1 100644 --- a/lib/domain/libimagnotes/src/notestore.rs +++ b/lib/domain/libimagnotes/src/notestore.rs @@ -19,14 +19,12 @@ use toml::Value; -use libimagstore::storeid::IntoStoreId; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use toml_query::insert::TomlValueInsertExt; use failure::Fallible as Result; -use module_path::ModuleEntryPath; use iter::*; pub trait NoteStore<'a> { @@ -45,9 +43,7 @@ impl<'a> NoteStore<'a> for Store { debug!("Creating new Note: '{}'", name); let fle = { - let mut lockentry = ModuleEntryPath::new(name.clone()) - .into_storeid() - .and_then(|id| self.create(id))?; + let mut lockentry = ::module_path::new_id(name.clone()).and_then(|id| self.create(id))?; { let entry = lockentry.deref_mut(); @@ -62,15 +58,15 @@ impl<'a> NoteStore<'a> for Store { } fn delete_note(&'a self, name: String) -> Result<()> { - ModuleEntryPath::new(name).into_storeid().and_then(|id| self.delete(id)) + ::module_path::new_id(name).and_then(|id| self.delete(id)) } fn retrieve_note(&'a self, name: String) -> Result> { - ModuleEntryPath::new(name).into_storeid().and_then(|id| self.retrieve(id)) + ::module_path::new_id(name).and_then(|id| self.retrieve(id)) } fn get_note(&'a self, name: String) -> Result>> { - ModuleEntryPath::new(name).into_storeid().and_then(|id| self.get(id)) + ::module_path::new_id(name).and_then(|id| self.get(id)) } fn all_notes(&'a self) -> Result { diff --git a/lib/domain/libimagtimetrack/src/iter/storeid.rs b/lib/domain/libimagtimetrack/src/iter/storeid.rs index 620925d1..2e2a0473 100644 --- a/lib/domain/libimagtimetrack/src/iter/storeid.rs +++ b/lib/domain/libimagtimetrack/src/iter/storeid.rs @@ -49,16 +49,12 @@ impl Iterator for TagStoreIdIter { type Item = Result<(StoreId, NDT)>; fn next(&mut self) -> Option { - use module_path::ModuleEntryPath; - use libimagstore::storeid::IntoStoreId; - self.inner .next() .map(|res| res.and_then(|tag| { let dt = self.datetime.format(DATE_TIME_FORMAT).to_string(); let id_str = format!("{}-{}", dt, tag.as_str()); - ModuleEntryPath::new(id_str) - .into_storeid() + ::module_path::new_id(id_str) .map_err(Error::from) .map(|id| (id, self.datetime.clone())) })) diff --git a/lib/domain/libimagtimetrack/src/lib.rs b/lib/domain/libimagtimetrack/src/lib.rs index b0064657..6335db17 100644 --- a/lib/domain/libimagtimetrack/src/lib.rs +++ b/lib/domain/libimagtimetrack/src/lib.rs @@ -45,7 +45,7 @@ extern crate toml_query; extern crate lazy_static; #[macro_use] extern crate is_match; -extern crate failure; +#[macro_use] extern crate failure; #[macro_use] extern crate libimagstore; diff --git a/lib/domain/libimagtodo/src/lib.rs b/lib/domain/libimagtodo/src/lib.rs index 0adf888b..bde8b818 100644 --- a/lib/domain/libimagtodo/src/lib.rs +++ b/lib/domain/libimagtodo/src/lib.rs @@ -42,7 +42,7 @@ extern crate toml; extern crate toml_query; #[macro_use] extern crate log; extern crate serde_json; -extern crate failure; +#[macro_use] extern crate failure; #[macro_use] extern crate libimagstore; extern crate libimagerror; diff --git a/lib/domain/libimagtodo/src/taskstore.rs b/lib/domain/libimagtodo/src/taskstore.rs index aca7890f..bbd2ae77 100644 --- a/lib/domain/libimagtodo/src/taskstore.rs +++ b/lib/domain/libimagtodo/src/taskstore.rs @@ -32,9 +32,7 @@ use failure::Error; use failure::err_msg; use libimagstore::store::{FileLockEntry, Store}; -use libimagstore::storeid::IntoStoreId; use libimagerror::errors::ErrorMsg as EM; -use module_path::ModuleEntryPath; use iter::TaskIdIterator; @@ -101,9 +99,7 @@ impl<'a> TaskStore<'a> for Store { /// /// If there is no task with this UUID, this returns `Ok(None)`. fn get_task_from_uuid(&'a self, uuid: Uuid) -> Result>> { - ModuleEntryPath::new(format!("taskwarrior/{}", uuid)) - .into_storeid() - .and_then(|store_id| self.get(store_id)) + ::module_path::new_id(format!("taskwarrior/{}", uuid)).and_then(|store_id| self.get(store_id)) } /// Same as Task::get_from_import() but uses Store::retrieve() rather than Store::get(), to @@ -154,9 +150,7 @@ impl<'a> TaskStore<'a> for Store { } fn delete_task_by_uuid(&self, uuid: Uuid) -> Result<()> { - ModuleEntryPath::new(format!("taskwarrior/{}", uuid)) - .into_storeid() - .and_then(|id| self.delete(id)) + ::module_path::new_id(format!("taskwarrior/{}", uuid)).and_then(|id| self.delete(id)) } fn all_tasks(&self) -> Result { @@ -168,24 +162,21 @@ impl<'a> TaskStore<'a> for Store { use toml_query::set::TomlValueSetExt; let uuid = task.uuid(); - ModuleEntryPath::new(format!("taskwarrior/{}", uuid)) - .into_storeid() - .and_then(|id| { - self.retrieve(id) - .and_then(|mut fle| { - { - let hdr = fle.get_header_mut(); - if hdr.read("todo")?.is_none() { - hdr.set("todo", Value::Table(BTreeMap::new()))?; - } + ::module_path::new_id(format!("taskwarrior/{}", uuid)).and_then(|id| { + self.retrieve(id).and_then(|mut fle| { + { + let hdr = fle.get_header_mut(); + if hdr.read("todo")?.is_none() { + hdr.set("todo", Value::Table(BTreeMap::new()))?; + } - hdr.set("todo.uuid", Value::String(format!("{}",uuid)))?; - } + hdr.set("todo.uuid", Value::String(format!("{}",uuid)))?; + } - // If none of the errors above have returned the function, everything is fine - Ok(fle) - }) + // If none of the errors above have returned the function, everything is fine + Ok(fle) }) + }) } diff --git a/lib/domain/libimagwiki/src/store.rs b/lib/domain/libimagwiki/src/store.rs index f0520398..a1e93e8a 100644 --- a/lib/domain/libimagwiki/src/store.rs +++ b/lib/domain/libimagwiki/src/store.rs @@ -20,7 +20,6 @@ use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use libimagstore::storeid::StoreId; -use libimagstore::storeid::IntoStoreId; use failure::Fallible as Result; @@ -83,6 +82,6 @@ impl WikiStore for Store { } fn wiki_path(name: &str) -> Result { - ::module_path::ModuleEntryPath::new(name).into_storeid() + ::module_path::new_id(name) } diff --git a/lib/domain/libimagwiki/src/wiki.rs b/lib/domain/libimagwiki/src/wiki.rs index 743536bf..195f46e2 100644 --- a/lib/domain/libimagwiki/src/wiki.rs +++ b/lib/domain/libimagwiki/src/wiki.rs @@ -21,7 +21,6 @@ use std::path::PathBuf; use libimagstore::store::Store; use libimagstore::store::FileLockEntry; -use libimagstore::storeid::IntoStoreId; use libimagstore::iter::Entries; use libimagentrylink::internal::InternalLinker; @@ -48,14 +47,14 @@ impl<'a, 'b> Wiki<'a, 'b> { pub(crate) fn create_index_page(&self) -> Result> { let path = PathBuf::from(format!("{}/index", self.1)); - let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?; + let sid = ::module_path::new_id(path)?; self.0.create(sid) } pub(crate) fn get_index_page(&self) -> Result> { let path = PathBuf::from(format!("{}/index", self.1)); - let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?; + let sid = ::module_path::new_id(path)?; self.0 .get(sid) @@ -64,14 +63,14 @@ impl<'a, 'b> Wiki<'a, 'b> { } pub fn get_entry>(&self, entry_name: EN) -> Result>> { - let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref())); - let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?; + let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref())); + let sid = ::module_path::new_id(path)?; self.0.get(sid) } pub fn create_entry>(&self, entry_name: EN) -> Result> { - let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref())); - let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?; + let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref())); + let sid = ::module_path::new_id(path)?; let mut index = self .get_entry("index")? .ok_or_else(|| err_msg("Missing index page"))?; @@ -81,8 +80,8 @@ impl<'a, 'b> Wiki<'a, 'b> { } pub fn retrieve_entry>(&self, entry_name: EN) -> Result> { - let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref())); - let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?; + let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref())); + let sid = ::module_path::new_id(path)?; let mut index = self .get_entry("index")? .ok_or_else(|| err_msg("Missing index page"))?; @@ -96,8 +95,8 @@ impl<'a, 'b> Wiki<'a, 'b> { } pub fn delete_entry>(&self, entry_name: EN) -> Result<()> { - let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref())); - let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?; + let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref())); + let sid = ::module_path::new_id(path)?; self.0.delete(sid) } } diff --git a/lib/entry/libimagentryannotation/src/annotateable.rs b/lib/entry/libimagentryannotation/src/annotateable.rs index 3c915846..19138e73 100644 --- a/lib/entry/libimagentryannotation/src/annotateable.rs +++ b/lib/entry/libimagentryannotation/src/annotateable.rs @@ -23,7 +23,6 @@ use uuid::Uuid; use libimagstore::store::Entry; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; -use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreIdIterator; use libimagentrylink::internal::InternalLinker; use libimagentryutil::isa::Is; @@ -36,8 +35,6 @@ use failure::ResultExt; use failure::Error; use failure::err_msg; -use module_path::ModuleEntryPath; - pub trait Annotateable { fn annotate<'a>(&mut self, store: &'a Store) -> Result>; fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result>>; @@ -54,7 +51,7 @@ impl Annotateable for Entry { let ann_name = Uuid::new_v4().to_hyphenated().to_string(); debug!("Creating annotation with name = {}", ann_name); - store.retrieve(ModuleEntryPath::new(ann_name.clone()).into_storeid()?) + store.retrieve(::module_path::new_id(ann_name.clone())?) .and_then(|mut anno| { { let _ = anno.set_isflag::()?; @@ -76,7 +73,7 @@ impl Annotateable for Entry { // Fails if there's no such annotation entry or if the link to that annotation entry does not // exist. fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result>> { - if let Some(mut annotation) = store.get(ModuleEntryPath::new(ann_name).into_storeid()?)? { + if let Some(mut annotation) = store.get(::module_path::new_id(ann_name)?)? { let _ = self.remove_internal_link(&mut annotation)?; Ok(Some(annotation)) } else { diff --git a/lib/entry/libimagentrycategory/src/lib.rs b/lib/entry/libimagentrycategory/src/lib.rs index a25813ea..c8096bc7 100644 --- a/lib/entry/libimagentrycategory/src/lib.rs +++ b/lib/entry/libimagentrycategory/src/lib.rs @@ -41,7 +41,7 @@ extern crate toml_query; extern crate toml; #[macro_use] extern crate log; -extern crate failure; +#[macro_use] extern crate failure; extern crate libimagerror; #[macro_use] extern crate libimagstore; diff --git a/lib/entry/libimagentrycategory/src/store.rs b/lib/entry/libimagentrycategory/src/store.rs index 88746bb1..508b3e8d 100644 --- a/lib/entry/libimagentrycategory/src/store.rs +++ b/lib/entry/libimagentrycategory/src/store.rs @@ -17,8 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::path::PathBuf; - use toml_query::insert::TomlValueInsertExt; use toml_query::read::TomlValueReadTypeExt; use toml::Value; @@ -60,7 +58,7 @@ impl CategoryStore for Store { /// Check whether a category exists fn category_exists(&self, name: &str) -> Result { trace!("Category exists? '{}'", name); - let sid = mk_category_storeid(self.path().clone(), name)?; + let sid = mk_category_storeid(name)?; represents_category(self, sid, name) } @@ -69,7 +67,7 @@ impl CategoryStore for Store { /// Fails if the category already exists (returns false then) fn create_category<'a>(&'a self, name: &str) -> Result> { trace!("Creating category: '{}'", name); - let sid = mk_category_storeid(self.path().clone(), name)?; + let sid = mk_category_storeid(name)?; let mut entry = self.create(sid)?; entry.set_isflag::()?; @@ -90,7 +88,7 @@ impl CategoryStore for Store { use category::Category; trace!("Deleting category: '{}'", name); - let sid = mk_category_storeid(self.path().clone(), name)?; + let sid = mk_category_storeid(name)?; { let mut category = self.get(sid.clone())? @@ -118,7 +116,7 @@ impl CategoryStore for Store { /// like a normal file in the store (which is exactly what it is). fn get_category_by_name(&self, name: &str) -> Result> { trace!("Getting category by name: '{}'", name); - let sid = mk_category_storeid(self.path().clone(), name)?; + let sid = mk_category_storeid(name)?; self.get(sid) .context(err_msg("Store write error")) @@ -209,12 +207,8 @@ mod tests { } #[inline] -fn mk_category_storeid(base: PathBuf, s: &str) -> Result { - use libimagstore::storeid::IntoStoreId; - ::module_path::ModuleEntryPath::new(s) - .into_storeid() - .context(err_msg("Store id handling error")) - .map_err(Error::from) +fn mk_category_storeid(s: &str) -> Result { + ::module_path::new_id(s).context(err_msg("Store id handling error")).map_err(Error::from) } #[inline] diff --git a/lib/entry/libimagentrylink/src/external.rs b/lib/entry/libimagentrylink/src/external.rs index bfce70a7..93627235 100644 --- a/lib/entry/libimagentrylink/src/external.rs +++ b/lib/entry/libimagentrylink/src/external.rs @@ -37,7 +37,6 @@ use std::fmt::Debug; use libimagstore::store::Entry; use libimagstore::store::Store; use libimagstore::storeid::StoreId; -use libimagstore::storeid::IntoStoreId; use libimagutil::debug_result::*; use libimagerror::errors::ErrorMsg as EM; @@ -50,7 +49,6 @@ use failure::ResultExt; use failure::err_msg; use internal::InternalLinker; -use module_path::ModuleEntryPath; use self::iter::*; @@ -337,12 +335,10 @@ impl ExternalLinker for Entry { debug!("Iterating {} links = {:?}", links.len(), links); links.into_iter().map(|link| { let hash = hex::encode(Sha1::digest(&link.as_str().as_bytes())); - let file_id = - ModuleEntryPath::new(format!("external/{}", hash)).into_storeid() - .map_dbg_err(|_| { - format!("Failed to build StoreId for this hash '{:?}'", hash) - }) - ?; + let file_id = ::module_path::new_id(format!("external/{}", hash)) + .map_dbg_err(|_| { + format!("Failed to build StoreId for this hash '{:?}'", hash) + })?; debug!("Link = '{:?}'", link); debug!("Hash = '{:?}'", hash); diff --git a/lib/entry/libimagentrylink/src/lib.rs b/lib/entry/libimagentrylink/src/lib.rs index 2ef064bf..ce258815 100644 --- a/lib/entry/libimagentrylink/src/lib.rs +++ b/lib/entry/libimagentrylink/src/lib.rs @@ -44,8 +44,8 @@ extern crate toml_query; extern crate url; extern crate sha1; extern crate hex; -#[macro_use] extern crate is_match; #[macro_use] extern crate failure; +#[macro_use] extern crate is_match; #[cfg(test)] extern crate env_logger;