Merge branch 'rewrite-module-entry-path'
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
commit
a4bcefe660
21 changed files with 75 additions and 137 deletions
|
@ -212,7 +212,7 @@ impl<'a> Display for StoreIdWithBase<'a> {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! module_entry_path_mod {
|
macro_rules! module_entry_path_mod {
|
||||||
($name:expr) => (
|
($name:expr) => (
|
||||||
#[deny(missing_docs,
|
#[allow(missing_docs,
|
||||||
missing_copy_implementations,
|
missing_copy_implementations,
|
||||||
trivial_casts, trivial_numeric_casts,
|
trivial_casts, trivial_numeric_casts,
|
||||||
unstable_features,
|
unstable_features,
|
||||||
|
@ -223,34 +223,23 @@ macro_rules! module_entry_path_mod {
|
||||||
use std::convert::AsRef;
|
use std::convert::AsRef;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use $crate::storeid::StoreId;
|
use $crate::storeid::StoreId;
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
|
||||||
/// A Struct giving you the ability to choose store entries assigned
|
pub fn new_id<P: AsRef<Path>>(p: P) -> Result<StoreId> {
|
||||||
/// to it.
|
|
||||||
///
|
|
||||||
/// It is created through a call to `new`.
|
|
||||||
pub struct ModuleEntryPath(PathBuf);
|
|
||||||
|
|
||||||
impl ModuleEntryPath {
|
let path_str = p
|
||||||
/// Path has to be a valid UTF-8 string or this will panic!
|
.as_ref()
|
||||||
pub fn new<P: AsRef<Path>>(pa: P) -> ModuleEntryPath {
|
.to_str()
|
||||||
let mut path = PathBuf::new();
|
.ok_or_else(|| {
|
||||||
path.push(format!("{}", $name));
|
format_err!("File path is not valid UTF-8: {}", p.as_ref().display())
|
||||||
path.push(pa.as_ref().clone());
|
})?;
|
||||||
let name = pa.as_ref().file_name().unwrap()
|
|
||||||
.to_str().unwrap();
|
let id = format!("{}/{}", $name, path_str);
|
||||||
path.set_file_name(name);
|
|
||||||
ModuleEntryPath(path)
|
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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use storeid::IntoStoreId;
|
|
||||||
|
|
||||||
module_entry_path_mod!("test");
|
module_entry_path_mod!("test");
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_correct_path() {
|
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]
|
#[test]
|
||||||
fn storeid_in_collection() {
|
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"]));
|
||||||
assert!(p.is_in_collection(&["test", "1", "2"]));
|
assert!(p.is_in_collection(&["test", "1", "2"]));
|
||||||
|
|
|
@ -28,12 +28,10 @@ use regex::Regex;
|
||||||
|
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
|
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagentrylink::external::ExternalLinker;
|
use libimagentrylink::external::ExternalLinker;
|
||||||
use libimagentrylink::external::iter::UrlIter;
|
use libimagentrylink::external::iter::UrlIter;
|
||||||
|
@ -53,22 +51,19 @@ pub trait BookmarkCollectionStore<'a> {
|
||||||
impl<'a> BookmarkCollectionStore<'a> for Store {
|
impl<'a> BookmarkCollectionStore<'a> for Store {
|
||||||
|
|
||||||
fn new(&'a self, name: &str) -> Result<FileLockEntry<'a>> {
|
fn new(&'a self, name: &str) -> Result<FileLockEntry<'a>> {
|
||||||
ModuleEntryPath::new(name)
|
::module_path::new_id(name)
|
||||||
.into_storeid()
|
|
||||||
.and_then(|id| self.create(id).map_err(Error::from))
|
.and_then(|id| self.create(id).map_err(Error::from))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(&'a self, name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
fn get(&'a self, name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
||||||
ModuleEntryPath::new(name)
|
::module_path::new_id(name)
|
||||||
.into_storeid()
|
|
||||||
.and_then(|id| self.get(id).map_err(Error::from))
|
.and_then(|id| self.get(id).map_err(Error::from))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete(&'a self, name: &str) -> Result<()> {
|
fn delete(&'a self, name: &str) -> Result<()> {
|
||||||
ModuleEntryPath::new(name)
|
::module_path::new_id(name)
|
||||||
.into_storeid()
|
|
||||||
.and_then(|id| self.delete(id).map_err(Error::from))
|
.and_then(|id| self.delete(id).map_err(Error::from))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
extern crate url;
|
extern crate url;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
extern crate failure;
|
#[macro_use] extern crate failure;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
|
|
|
@ -27,7 +27,6 @@ use vobject::vcard::Vcard;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::iter::Entries;
|
use libimagstore::iter::Entries;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
|
@ -36,7 +35,6 @@ use libimagentryutil::isa::Is;
|
||||||
|
|
||||||
use contact::IsContact;
|
use contact::IsContact;
|
||||||
use deser::DeserVcard;
|
use deser::DeserVcard;
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
use util;
|
use util;
|
||||||
|
|
||||||
pub trait ContactStore<'a> {
|
pub trait ContactStore<'a> {
|
||||||
|
@ -98,7 +96,7 @@ fn prepare_fetching_from_store(buf: &str) -> Result<(StoreId, Value)> {
|
||||||
toml_from_str::<Value>(&serialized)?
|
toml_from_str::<Value>(&serialized)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let sid = ModuleEntryPath::new(uid.raw()).into_storeid()?;
|
let sid = ::module_path::new_id(uid.raw())?;
|
||||||
|
|
||||||
Ok((sid, value))
|
Ok((sid, value))
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,6 @@ use failure::err_msg;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
use libimagstore::storeid::IntoStoreId;
|
||||||
|
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
|
||||||
pub struct DiaryId {
|
pub struct DiaryId {
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -150,8 +148,9 @@ impl DiaryId {
|
||||||
impl IntoStoreId for DiaryId {
|
impl IntoStoreId for DiaryId {
|
||||||
|
|
||||||
fn into_storeid(self) -> Result<StoreId> {
|
fn into_storeid(self) -> Result<StoreId> {
|
||||||
|
use std::path::PathBuf;
|
||||||
let s : String = self.into();
|
let s : String = self.into();
|
||||||
ModuleEntryPath::new(s).into_storeid()
|
::module_path::new_id(PathBuf::from(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ extern crate chrono;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
extern crate toml_query;
|
extern crate toml_query;
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate failure;
|
#[macro_use] extern crate failure;
|
||||||
extern crate filters;
|
extern crate filters;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
|
|
|
@ -37,7 +37,6 @@ use libimagstore::store::Store;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
use libimagstore::storeid::StoreIdIterator;
|
||||||
use libimagentryutil::isa::Is;
|
use libimagentryutil::isa::Is;
|
||||||
use libimagentryutil::isa::IsKindHeaderPathProvider;
|
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<StoreId> {
|
fn instance_id_for_name_and_datestr(habit_name: &String, habit_date: &String) -> Result<StoreId> {
|
||||||
use module_path::ModuleEntryPath;
|
::module_path::new_id(format!("instance/{}-{}", habit_name, habit_date)).map_err(Error::from)
|
||||||
|
|
||||||
ModuleEntryPath::new(format!("instance/{}-{}", habit_name, habit_date))
|
|
||||||
.into_storeid()
|
|
||||||
.map_err(Error::from)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod builder {
|
pub mod builder {
|
||||||
|
@ -272,7 +267,6 @@ pub mod builder {
|
||||||
|
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagentryutil::isa::Is;
|
use libimagentryutil::isa::Is;
|
||||||
use libimagutil::debug_result::DebugResult;
|
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
|
/// Buld a StoreId for a Habit from a date object and a name of a habit
|
||||||
fn build_habit_template_sid(name: &String) -> Result<StoreId> {
|
fn build_habit_template_sid(name: &String) -> Result<StoreId> {
|
||||||
use module_path::ModuleEntryPath;
|
::module_path::new_id(format!("template/{}", name)).map_err(From::from)
|
||||||
ModuleEntryPath::new(format!("template/{}", name)).into_storeid().map_err(From::from)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ use toml_query::insert::TomlValueInsertExt;
|
||||||
|
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::iter::Entries;
|
use libimagstore::iter::Entries;
|
||||||
use libimagentryref::hasher::default::DefaultHasher;
|
use libimagentryref::hasher::default::DefaultHasher;
|
||||||
|
@ -36,7 +35,6 @@ use libimagentryref::reference::RefFassade;
|
||||||
use libimagentryref::reference::Ref;
|
use libimagentryref::reference::Ref;
|
||||||
use libimagentryref::reference::MutRef;
|
use libimagentryref::reference::MutRef;
|
||||||
|
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
use mid::MessageId;
|
use mid::MessageId;
|
||||||
use mail::Mail;
|
use mail::Mail;
|
||||||
use hasher::MailHasher;
|
use hasher::MailHasher;
|
||||||
|
@ -69,7 +67,7 @@ impl<'a> MailStore<'a> for Store {
|
||||||
CollName: AsRef<str> + Debug
|
CollName: AsRef<str> + Debug
|
||||||
{
|
{
|
||||||
let message_id = get_message_id_for_mailfile(p.as_ref())?;
|
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 mut entry = self.create(new_sid)?;
|
||||||
let _ = entry
|
let _ = entry
|
||||||
|
@ -90,7 +88,7 @@ impl<'a> MailStore<'a> for Store {
|
||||||
where P: AsRef<Path> + Debug
|
where P: AsRef<Path> + Debug
|
||||||
{
|
{
|
||||||
let message_id = get_message_id_for_mailfile(p.as_ref())?;
|
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)? {
|
match self.get(new_sid)? {
|
||||||
Some(mut entry) => {
|
Some(mut entry) => {
|
||||||
|
@ -117,7 +115,7 @@ impl<'a> MailStore<'a> for Store {
|
||||||
CollName: AsRef<str> + Debug
|
CollName: AsRef<str> + Debug
|
||||||
{
|
{
|
||||||
let message_id = get_message_id_for_mailfile(&p)?;
|
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 mut entry = self.retrieve(new_sid)?;
|
||||||
|
|
||||||
let _ = entry
|
let _ = entry
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
extern crate toml_query;
|
extern crate toml_query;
|
||||||
extern crate failure;
|
#[macro_use] extern crate failure;
|
||||||
|
|
||||||
extern crate libimagrt;
|
extern crate libimagrt;
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
|
|
|
@ -19,14 +19,12 @@
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
|
|
||||||
use toml_query::insert::TomlValueInsertExt;
|
use toml_query::insert::TomlValueInsertExt;
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
use iter::*;
|
use iter::*;
|
||||||
|
|
||||||
pub trait NoteStore<'a> {
|
pub trait NoteStore<'a> {
|
||||||
|
@ -45,9 +43,7 @@ impl<'a> NoteStore<'a> for Store {
|
||||||
|
|
||||||
debug!("Creating new Note: '{}'", name);
|
debug!("Creating new Note: '{}'", name);
|
||||||
let fle = {
|
let fle = {
|
||||||
let mut lockentry = ModuleEntryPath::new(name.clone())
|
let mut lockentry = ::module_path::new_id(name.clone()).and_then(|id| self.create(id))?;
|
||||||
.into_storeid()
|
|
||||||
.and_then(|id| self.create(id))?;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let entry = lockentry.deref_mut();
|
let entry = lockentry.deref_mut();
|
||||||
|
@ -62,15 +58,15 @@ impl<'a> NoteStore<'a> for Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_note(&'a self, name: String) -> Result<()> {
|
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<FileLockEntry<'a>> {
|
fn retrieve_note(&'a self, name: String) -> Result<FileLockEntry<'a>> {
|
||||||
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<Option<FileLockEntry<'a>>> {
|
fn get_note(&'a self, name: String) -> Result<Option<FileLockEntry<'a>>> {
|
||||||
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<NoteIterator> {
|
fn all_notes(&'a self) -> Result<NoteIterator> {
|
||||||
|
|
|
@ -49,16 +49,12 @@ impl Iterator for TagStoreIdIter {
|
||||||
type Item = Result<(StoreId, NDT)>;
|
type Item = Result<(StoreId, NDT)>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
|
|
||||||
self.inner
|
self.inner
|
||||||
.next()
|
.next()
|
||||||
.map(|res| res.and_then(|tag| {
|
.map(|res| res.and_then(|tag| {
|
||||||
let dt = self.datetime.format(DATE_TIME_FORMAT).to_string();
|
let dt = self.datetime.format(DATE_TIME_FORMAT).to_string();
|
||||||
let id_str = format!("{}-{}", dt, tag.as_str());
|
let id_str = format!("{}-{}", dt, tag.as_str());
|
||||||
ModuleEntryPath::new(id_str)
|
::module_path::new_id(id_str)
|
||||||
.into_storeid()
|
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map(|id| (id, self.datetime.clone()))
|
.map(|id| (id, self.datetime.clone()))
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -45,7 +45,7 @@ extern crate toml_query;
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate is_match;
|
extern crate is_match;
|
||||||
extern crate failure;
|
#[macro_use] extern crate failure;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
|
|
|
@ -42,7 +42,7 @@ extern crate toml;
|
||||||
extern crate toml_query;
|
extern crate toml_query;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate failure;
|
#[macro_use] extern crate failure;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
|
|
|
@ -32,9 +32,7 @@ use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use libimagstore::store::{FileLockEntry, Store};
|
use libimagstore::store::{FileLockEntry, Store};
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
use libimagerror::errors::ErrorMsg as EM;
|
use libimagerror::errors::ErrorMsg as EM;
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
|
|
||||||
use iter::TaskIdIterator;
|
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)`.
|
/// If there is no task with this UUID, this returns `Ok(None)`.
|
||||||
fn get_task_from_uuid(&'a self, uuid: Uuid) -> Result<Option<FileLockEntry<'a>>> {
|
fn get_task_from_uuid(&'a self, uuid: Uuid) -> Result<Option<FileLockEntry<'a>>> {
|
||||||
ModuleEntryPath::new(format!("taskwarrior/{}", uuid))
|
::module_path::new_id(format!("taskwarrior/{}", uuid)).and_then(|store_id| self.get(store_id))
|
||||||
.into_storeid()
|
|
||||||
.and_then(|store_id| self.get(store_id))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as Task::get_from_import() but uses Store::retrieve() rather than Store::get(), to
|
/// 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<()> {
|
fn delete_task_by_uuid(&self, uuid: Uuid) -> Result<()> {
|
||||||
ModuleEntryPath::new(format!("taskwarrior/{}", uuid))
|
::module_path::new_id(format!("taskwarrior/{}", uuid)).and_then(|id| self.delete(id))
|
||||||
.into_storeid()
|
|
||||||
.and_then(|id| self.delete(id))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_tasks(&self) -> Result<TaskIdIterator> {
|
fn all_tasks(&self) -> Result<TaskIdIterator> {
|
||||||
|
@ -168,24 +162,21 @@ impl<'a> TaskStore<'a> for Store {
|
||||||
use toml_query::set::TomlValueSetExt;
|
use toml_query::set::TomlValueSetExt;
|
||||||
|
|
||||||
let uuid = task.uuid();
|
let uuid = task.uuid();
|
||||||
ModuleEntryPath::new(format!("taskwarrior/{}", uuid))
|
::module_path::new_id(format!("taskwarrior/{}", uuid)).and_then(|id| {
|
||||||
.into_storeid()
|
self.retrieve(id).and_then(|mut fle| {
|
||||||
.and_then(|id| {
|
{
|
||||||
self.retrieve(id)
|
let hdr = fle.get_header_mut();
|
||||||
.and_then(|mut fle| {
|
if hdr.read("todo")?.is_none() {
|
||||||
{
|
hdr.set("todo", Value::Table(BTreeMap::new()))?;
|
||||||
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
|
// If none of the errors above have returned the function, everything is fine
|
||||||
Ok(fle)
|
Ok(fle)
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
|
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
|
||||||
|
@ -83,6 +82,6 @@ impl WikiStore for Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wiki_path(name: &str) -> Result<StoreId> {
|
fn wiki_path(name: &str) -> Result<StoreId> {
|
||||||
::module_path::ModuleEntryPath::new(name).into_storeid()
|
::module_path::new_id(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
|
||||||
use libimagstore::iter::Entries;
|
use libimagstore::iter::Entries;
|
||||||
use libimagentrylink::internal::InternalLinker;
|
use libimagentrylink::internal::InternalLinker;
|
||||||
|
|
||||||
|
@ -48,14 +47,14 @@ impl<'a, 'b> Wiki<'a, 'b> {
|
||||||
|
|
||||||
pub(crate) fn create_index_page(&self) -> Result<FileLockEntry<'a>> {
|
pub(crate) fn create_index_page(&self) -> Result<FileLockEntry<'a>> {
|
||||||
let path = PathBuf::from(format!("{}/index", self.1));
|
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)
|
self.0.create(sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_index_page(&self) -> Result<FileLockEntry<'a>> {
|
pub(crate) fn get_index_page(&self) -> Result<FileLockEntry<'a>> {
|
||||||
let path = PathBuf::from(format!("{}/index", self.1));
|
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
|
self.0
|
||||||
.get(sid)
|
.get(sid)
|
||||||
|
@ -64,14 +63,14 @@ impl<'a, 'b> Wiki<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<Option<FileLockEntry<'a>>> {
|
pub fn get_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<Option<FileLockEntry<'a>>> {
|
||||||
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
||||||
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
|
let sid = ::module_path::new_id(path)?;
|
||||||
self.0.get(sid)
|
self.0.get(sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<FileLockEntry<'a>> {
|
pub fn create_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<FileLockEntry<'a>> {
|
||||||
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
||||||
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
|
let sid = ::module_path::new_id(path)?;
|
||||||
let mut index = self
|
let mut index = self
|
||||||
.get_entry("index")?
|
.get_entry("index")?
|
||||||
.ok_or_else(|| err_msg("Missing index page"))?;
|
.ok_or_else(|| err_msg("Missing index page"))?;
|
||||||
|
@ -81,8 +80,8 @@ impl<'a, 'b> Wiki<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retrieve_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<FileLockEntry<'a>> {
|
pub fn retrieve_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<FileLockEntry<'a>> {
|
||||||
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
||||||
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
|
let sid = ::module_path::new_id(path)?;
|
||||||
let mut index = self
|
let mut index = self
|
||||||
.get_entry("index")?
|
.get_entry("index")?
|
||||||
.ok_or_else(|| err_msg("Missing index page"))?;
|
.ok_or_else(|| err_msg("Missing index page"))?;
|
||||||
|
@ -96,8 +95,8 @@ impl<'a, 'b> Wiki<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<()> {
|
pub fn delete_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<()> {
|
||||||
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
||||||
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
|
let sid = ::module_path::new_id(path)?;
|
||||||
self.0.delete(sid)
|
self.0.delete(sid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ use uuid::Uuid;
|
||||||
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::storeid::IntoStoreId;
|
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
use libimagstore::storeid::StoreIdIterator;
|
||||||
use libimagentrylink::internal::InternalLinker;
|
use libimagentrylink::internal::InternalLinker;
|
||||||
use libimagentryutil::isa::Is;
|
use libimagentryutil::isa::Is;
|
||||||
|
@ -36,8 +35,6 @@ use failure::ResultExt;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
|
|
||||||
pub trait Annotateable {
|
pub trait Annotateable {
|
||||||
fn annotate<'a>(&mut self, store: &'a Store) -> Result<FileLockEntry<'a>>;
|
fn annotate<'a>(&mut self, store: &'a Store) -> Result<FileLockEntry<'a>>;
|
||||||
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>>;
|
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>>;
|
||||||
|
@ -54,7 +51,7 @@ impl Annotateable for Entry {
|
||||||
let ann_name = Uuid::new_v4().to_hyphenated().to_string();
|
let ann_name = Uuid::new_v4().to_hyphenated().to_string();
|
||||||
debug!("Creating annotation with name = {}", ann_name);
|
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| {
|
.and_then(|mut anno| {
|
||||||
{
|
{
|
||||||
let _ = anno.set_isflag::<IsAnnotation>()?;
|
let _ = anno.set_isflag::<IsAnnotation>()?;
|
||||||
|
@ -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
|
// Fails if there's no such annotation entry or if the link to that annotation entry does not
|
||||||
// exist.
|
// exist.
|
||||||
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
||||||
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)?;
|
let _ = self.remove_internal_link(&mut annotation)?;
|
||||||
Ok(Some(annotation))
|
Ok(Some(annotation))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -41,7 +41,7 @@ extern crate toml_query;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate failure;
|
#[macro_use] extern crate failure;
|
||||||
|
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
// 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::path::PathBuf;
|
|
||||||
|
|
||||||
use toml_query::insert::TomlValueInsertExt;
|
use toml_query::insert::TomlValueInsertExt;
|
||||||
use toml_query::read::TomlValueReadTypeExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
@ -60,7 +58,7 @@ impl CategoryStore for Store {
|
||||||
/// Check whether a category exists
|
/// Check whether a category exists
|
||||||
fn category_exists(&self, name: &str) -> Result<bool> {
|
fn category_exists(&self, name: &str) -> Result<bool> {
|
||||||
trace!("Category exists? '{}'", name);
|
trace!("Category exists? '{}'", name);
|
||||||
let sid = mk_category_storeid(self.path().clone(), name)?;
|
let sid = mk_category_storeid(name)?;
|
||||||
represents_category(self, sid, name)
|
represents_category(self, sid, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +67,7 @@ impl CategoryStore for Store {
|
||||||
/// Fails if the category already exists (returns false then)
|
/// Fails if the category already exists (returns false then)
|
||||||
fn create_category<'a>(&'a self, name: &str) -> Result<FileLockEntry<'a>> {
|
fn create_category<'a>(&'a self, name: &str) -> Result<FileLockEntry<'a>> {
|
||||||
trace!("Creating category: '{}'", name);
|
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)?;
|
let mut entry = self.create(sid)?;
|
||||||
|
|
||||||
entry.set_isflag::<IsCategory>()?;
|
entry.set_isflag::<IsCategory>()?;
|
||||||
|
@ -90,7 +88,7 @@ impl CategoryStore for Store {
|
||||||
use category::Category;
|
use category::Category;
|
||||||
|
|
||||||
trace!("Deleting category: '{}'", name);
|
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())?
|
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).
|
/// like a normal file in the store (which is exactly what it is).
|
||||||
fn get_category_by_name(&self, name: &str) -> Result<Option<FileLockEntry>> {
|
fn get_category_by_name(&self, name: &str) -> Result<Option<FileLockEntry>> {
|
||||||
trace!("Getting category by name: '{}'", name);
|
trace!("Getting category by name: '{}'", name);
|
||||||
let sid = mk_category_storeid(self.path().clone(), name)?;
|
let sid = mk_category_storeid(name)?;
|
||||||
|
|
||||||
self.get(sid)
|
self.get(sid)
|
||||||
.context(err_msg("Store write error"))
|
.context(err_msg("Store write error"))
|
||||||
|
@ -209,12 +207,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn mk_category_storeid(base: PathBuf, s: &str) -> Result<StoreId> {
|
fn mk_category_storeid(s: &str) -> Result<StoreId> {
|
||||||
use libimagstore::storeid::IntoStoreId;
|
::module_path::new_id(s).context(err_msg("Store id handling error")).map_err(Error::from)
|
||||||
::module_path::ModuleEntryPath::new(s)
|
|
||||||
.into_storeid()
|
|
||||||
.context(err_msg("Store id handling error"))
|
|
||||||
.map_err(Error::from)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -37,7 +37,6 @@ use std::fmt::Debug;
|
||||||
use libimagstore::store::Entry;
|
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 libimagutil::debug_result::*;
|
use libimagutil::debug_result::*;
|
||||||
use libimagerror::errors::ErrorMsg as EM;
|
use libimagerror::errors::ErrorMsg as EM;
|
||||||
|
|
||||||
|
@ -50,7 +49,6 @@ use failure::ResultExt;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use internal::InternalLinker;
|
use internal::InternalLinker;
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
|
|
||||||
use self::iter::*;
|
use self::iter::*;
|
||||||
|
|
||||||
|
@ -337,12 +335,10 @@ impl ExternalLinker for Entry {
|
||||||
debug!("Iterating {} links = {:?}", links.len(), links);
|
debug!("Iterating {} links = {:?}", links.len(), links);
|
||||||
links.into_iter().map(|link| {
|
links.into_iter().map(|link| {
|
||||||
let hash = hex::encode(Sha1::digest(&link.as_str().as_bytes()));
|
let hash = hex::encode(Sha1::digest(&link.as_str().as_bytes()));
|
||||||
let file_id =
|
let file_id = ::module_path::new_id(format!("external/{}", hash))
|
||||||
ModuleEntryPath::new(format!("external/{}", hash)).into_storeid()
|
.map_dbg_err(|_| {
|
||||||
.map_dbg_err(|_| {
|
format!("Failed to build StoreId for this hash '{:?}'", hash)
|
||||||
format!("Failed to build StoreId for this hash '{:?}'", hash)
|
})?;
|
||||||
})
|
|
||||||
?;
|
|
||||||
|
|
||||||
debug!("Link = '{:?}'", link);
|
debug!("Link = '{:?}'", link);
|
||||||
debug!("Hash = '{:?}'", hash);
|
debug!("Hash = '{:?}'", hash);
|
||||||
|
|
|
@ -44,8 +44,8 @@ extern crate toml_query;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
extern crate sha1;
|
extern crate sha1;
|
||||||
extern crate hex;
|
extern crate hex;
|
||||||
#[macro_use] extern crate is_match;
|
|
||||||
#[macro_use] extern crate failure;
|
#[macro_use] extern crate failure;
|
||||||
|
#[macro_use] extern crate is_match;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
|
|
Loading…
Reference in a new issue