summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-02-15 22:15:58 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-02-15 22:15:58 +0100
commita6ad19a14f16c5344ea65df3efcc00464b2ad9aa (patch)
tree2d84c1a8021fe8b16faf6ef75e0b4a0b24cba8d0
parent08b7a46c74c37d7179d7b9332e8e165faa056ffc (diff)
parent6fd2c9b958ec17e5eb4bcfc365df126a89540bce (diff)
Merge branch 'redefine-storeid'
Finally merging the redefine of the StoreId implementation, which allows easier handling of StoreId objects. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/core/imag-annotate/src/main.rs2
-rw-r--r--bin/core/imag-ids/src/main.rs20
-rw-r--r--bin/core/imag-link/src/main.rs11
-rw-r--r--bin/core/imag-mv/src/main.rs4
-rw-r--r--bin/core/imag-store/src/create.rs3
-rw-r--r--bin/core/imag-store/src/delete.rs3
-rw-r--r--bin/core/imag-store/src/get.rs3
-rw-r--r--bin/core/imag-store/src/retrieve.rs3
-rw-r--r--bin/core/imag-store/src/update.rs3
-rw-r--r--bin/core/imag-tag/src/main.rs12
-rw-r--r--bin/domain/imag-contact/src/main.rs7
-rw-r--r--lib/core/libimagrt/src/runtime.rs8
-rw-r--r--lib/core/libimagstore/src/file_abstraction/fs.rs12
-rw-r--r--lib/core/libimagstore/src/file_abstraction/inmemory.rs8
-rw-r--r--lib/core/libimagstore/src/file_abstraction/iter.rs32
-rw-r--r--lib/core/libimagstore/src/file_abstraction/mod.rs33
-rw-r--r--lib/core/libimagstore/src/iter.rs29
-rw-r--r--lib/core/libimagstore/src/lib.rs2
-rw-r--r--lib/core/libimagstore/src/store.rs103
-rw-r--r--lib/core/libimagstore/src/storeid.rs236
-rw-r--r--lib/domain/libimagcontact/src/store.rs8
-rw-r--r--lib/domain/libimagdiary/src/diary.rs4
-rw-r--r--lib/domain/libimaghabit/src/iter.rs4
-rw-r--r--lib/domain/libimaghabit/src/store.rs4
-rw-r--r--lib/domain/libimagnotes/src/notestore.rs2
-rw-r--r--lib/domain/libimagtimetrack/src/iter/mod.rs7
-rw-r--r--lib/domain/libimagtimetrack/src/tag.rs2
-rw-r--r--lib/domain/libimagtodo/src/iter.rs10
-rw-r--r--lib/domain/libimagtodo/src/taskstore.rs2
-rw-r--r--lib/domain/libimagwiki/src/wiki.rs6
-rw-r--r--lib/entry/libimagentryannotation/src/annotation_fetcher.rs12
-rw-r--r--lib/entry/libimagentrycategory/src/store.rs8
-rw-r--r--lib/entry/libimagentrydatetime/src/datepath/compiler.rs2
-rw-r--r--lib/entry/libimagentrydatetime/src/datetime.rs5
-rw-r--r--lib/entry/libimagentrygps/src/entry.rs5
-rw-r--r--lib/entry/libimagentrylink/src/external.rs5
-rw-r--r--lib/entry/libimagentrylink/src/internal.rs65
-rw-r--r--lib/entry/libimagentrymarkdown/src/processor.rs18
-rw-r--r--lib/entry/libimagentryref/src/refstore.rs4
-rw-r--r--lib/etc/libimaginteraction/src/ui.rs4
40 files changed, 296 insertions, 415 deletions
diff --git a/bin/core/imag-annotate/src/main.rs b/bin/core/imag-annotate/src/main.rs
index c764758d..ada33757 100644
--- a/bin/core/imag-annotate/src/main.rs
+++ b/bin/core/imag-annotate/src/main.rs
@@ -208,7 +208,7 @@ fn list(rt: &Runtime) {
rt.store()
.all_annotations()
.map_err_trace_exit_unwrap()
- .into_get_iter(rt.store())
+ .into_get_iter()
.trace_unwrap_exit()
.map(|opt| opt.ok_or_else(|| format_err!("Cannot find entry")))
.trace_unwrap_exit()
diff --git a/bin/core/imag-ids/src/main.rs b/bin/core/imag-ids/src/main.rs
index 72c07b6a..b0b84199 100644
--- a/bin/core/imag-ids/src/main.rs
+++ b/bin/core/imag-ids/src/main.rs
@@ -118,23 +118,27 @@ fn main() {
}
})
.map(|id| if print_storepath {
- id
+ (Some(rt.store().path()), id)
} else {
- id.without_base()
+ (None, id)
});
let mut stdout = rt.stdout();
trace!("Got output: {:?}", stdout);
- iterator.for_each(|id| {
- let _ = rt.report_touched(&id).unwrap_or_exit(); // .map_err_trace_exit_unwrap();
-
+ iterator.for_each(|(storepath, id)| {
+ rt.report_touched(&id).unwrap_or_exit();
if !rt.output_is_pipe() {
let id = id.to_str().map_err_trace_exit_unwrap();
trace!("Writing to {:?}", stdout);
- writeln!(stdout, "{}", id)
- .to_exit_code()
- .unwrap_or_exit();
+
+ let result = if let Some(store) = storepath {
+ writeln!(stdout, "{}/{}", store.display(), id)
+ } else {
+ writeln!(stdout, "{}", id)
+ };
+
+ result.to_exit_code().unwrap_or_exit();
}
})
}
diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs
index dc9be715..cfd2c4fe 100644
--- a/bin/core/imag-link/src/main.rs
+++ b/bin/core/imag-link/src/main.rs
@@ -132,8 +132,7 @@ fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockE
use libimagstore::storeid::StoreId;
debug!("Getting: {:?}", name);
- let result = StoreId::new(Some(rt.store().path().clone()), PathBuf::from(name))
- .and_then(|id| rt.store().get(id));
+ let result = StoreId::new(PathBuf::from(name)).and_then(|id| rt.store().get(id));
debug!(" => : {:?}", result);
result
@@ -168,8 +167,8 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
} else {
debug!("Linking internally: {:?} -> {:?}", from, entry);
- let from_id = StoreId::new_baseless(PathBuf::from(from)).map_err_trace_exit_unwrap();
- let entr_id = StoreId::new_baseless(PathBuf::from(entry)).map_err_trace_exit_unwrap();
+ let from_id = StoreId::new(PathBuf::from(from)).map_err_trace_exit_unwrap();
+ let entr_id = StoreId::new(PathBuf::from(entry)).map_err_trace_exit_unwrap();
if from_id == entr_id {
error!("Cannot link entry with itself. Exiting");
@@ -366,13 +365,13 @@ mod tests {
let mut path = PathBuf::new();
path.set_file_name(name);
- let default_entry = Entry::new(StoreId::new_baseless(PathBuf::from("")).unwrap())
+ let default_entry = Entry::new(StoreId::new(PathBuf::from("")).unwrap())
.to_str()
.unwrap();
debug!("Default entry constructed");
- let id = StoreId::new_baseless(path)?;
+ let id = StoreId::new(path)?;
debug!("StoreId constructed: {:?}", id);
let mut entry = rt.store().create(id.clone())?;
diff --git a/bin/core/imag-mv/src/main.rs b/bin/core/imag-mv/src/main.rs
index ff267067..f5d4d341 100644
--- a/bin/core/imag-mv/src/main.rs
+++ b/bin/core/imag-mv/src/main.rs
@@ -72,7 +72,7 @@ fn main() {
.cli()
.value_of("source")
.map(PathBuf::from)
- .map(StoreId::new_baseless)
+ .map(StoreId::new)
.unwrap() // unwrap safe by clap
.map_err_trace_exit_unwrap();
@@ -80,7 +80,7 @@ fn main() {
.cli()
.value_of("dest")
.map(PathBuf::from)
- .map(StoreId::new_baseless)
+ .map(StoreId::new)
.unwrap() // unwrap safe by clap
.map_err_trace_exit_unwrap();
diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs
index c6830a42..8b6cc2e2 100644
--- a/bin/core/imag-store/src/create.rs
+++ b/bin/core/imag-store/src/create.rs
@@ -44,8 +44,7 @@ pub fn create(rt: &Runtime) {
// unwrap is safe as value is required
let path = scmd.value_of("path").unwrap();
let path = PathBuf::from(path);
- let store = Some(rt.store().path().clone());
- let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
+ let path = StoreId::new(path).map_err_trace_exit_unwrap();
debug!("path = {:?}", path);
diff --git a/bin/core/imag-store/src/delete.rs b/bin/core/imag-store/src/delete.rs
index bc1672b4..50c73d97 100644
--- a/bin/core/imag-store/src/delete.rs
+++ b/bin/core/imag-store/src/delete.rs
@@ -28,8 +28,7 @@ pub fn delete(rt: &Runtime) {
let scmd = rt.cli().subcommand_matches("delete").unwrap();
let id = scmd.value_of("id").unwrap(); // safe by clap
let path = PathBuf::from(id);
- let store = Some(rt.store().path().clone());
- let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
+ let path = StoreId::new(path).map_err_trace_exit_unwrap();
debug!("Deleting file at {:?}", id);
let _ = rt.store()
diff --git a/bin/core/imag-store/src/get.rs b/bin/core/imag-store/src/get.rs
index 582e67d7..bf9a1eea 100644
--- a/bin/core/imag-store/src/get.rs
+++ b/bin/core/imag-store/src/get.rs
@@ -31,8 +31,7 @@ pub fn get(rt: &Runtime) {
let id = scmd.value_of("id").unwrap(); // safe by clap
let path = PathBuf::from(id);
- let store = Some(rt.store().path().clone());
- let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
+ let path = StoreId::new(path).map_err_trace_exit_unwrap();
debug!("path = {:?}", path);
let _ = match rt.store().get(path.clone()).map_err_trace_exit_unwrap() {
diff --git a/bin/core/imag-store/src/retrieve.rs b/bin/core/imag-store/src/retrieve.rs
index e1fafce8..b359a3c4 100644
--- a/bin/core/imag-store/src/retrieve.rs
+++ b/bin/core/imag-store/src/retrieve.rs
@@ -37,8 +37,7 @@ pub fn retrieve(rt: &Runtime) {
// unwrap() is safe as arg is required
let id = scmd.value_of("id").unwrap();
let path = PathBuf::from(id);
- let store = Some(rt.store().path().clone());
- let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
+ let path = StoreId::new(path).map_err_trace_exit_unwrap();
debug!("path = {:?}", path);
rt.store()
diff --git a/bin/core/imag-store/src/update.rs b/bin/core/imag-store/src/update.rs
index cad2fd57..c2687973 100644
--- a/bin/core/imag-store/src/update.rs
+++ b/bin/core/imag-store/src/update.rs
@@ -31,8 +31,7 @@ pub fn update(rt: &Runtime) {
let scmd = rt.cli().subcommand_matches("update").unwrap();
let id = scmd.value_of("id").unwrap(); // Safe by clap
let path = PathBuf::from(id);
- let store = Some(rt.store().path().clone());
- let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
+ let path = StoreId::new(path).map_err_trace_exit_unwrap();
let _ = rt.store()
.retrieve(path)
diff --git a/bin/core/imag-tag/src/main.rs b/bin/core/imag-tag/src/main.rs
index ddf3fa70..e3ba7f20 100644
--- a/bin/core/imag-tag/src/main.rs
+++ b/bin/core/imag-tag/src/main.rs
@@ -264,11 +264,11 @@ mod tests {
let mut path = PathBuf::new();
path.set_file_name(name);
- let default_entry = Entry::new(StoreId::new_baseless(PathBuf::from("")).unwrap())
+ let default_entry = Entry::new(StoreId::new(PathBuf::from("")).unwrap())
.to_str()
.unwrap();
- let id = StoreId::new_baseless(path)?;
+ let id = StoreId::new(path)?;
let mut entry = rt.store().create(id.clone())?;
entry.get_content_mut().push_str(&default_entry);
@@ -303,7 +303,7 @@ mod tests {
debug!("Add-tags: {:?}", add);
debug!("Altering things");
- alter(&rt, StoreId::new_baseless(id.clone()).unwrap(), add, None);
+ alter(&rt, StoreId::new(id.clone()).unwrap(), add, None);
debug!("Altered");
let test_entry = rt.store().get(id).unwrap().unwrap();
@@ -338,7 +338,7 @@ mod tests {
debug!("Rem-tags: {:?}", rem);
debug!("Altering things");
- alter(&rt, StoreId::new_baseless(id.clone()).unwrap(), add, rem);
+ alter(&rt, StoreId::new(id.clone()).unwrap(), add, rem);
debug!("Altered");
let test_entry = rt.store().get(id).unwrap().unwrap();
@@ -366,7 +366,7 @@ mod tests {
debug!("Rem-tags: {:?}", rem);
debug!("Altering things");
- alter(&rt, StoreId::new_baseless(id.clone()).unwrap(), add, rem);
+ alter(&rt, StoreId::new(id.clone()).unwrap(), add, rem);
debug!("Altered");
let test_entry = rt.store().get(id).unwrap().unwrap();
@@ -394,7 +394,7 @@ mod tests {
debug!("Rem-tags: {:?}", rem);
debug!("Altering things");
- alter(&rt, StoreId::new_baseless(id.clone()).unwrap(), add, rem);
+ alter(&rt, StoreId::new(id.clone()).unwrap(), add, rem);
debug!("Altered");
let test_entry = rt.store().get(id).unwrap().unwrap();
diff --git a/bin/domain/imag-contact/src/main.rs b/bin/domain/imag-contact/src/main.rs
index 9570e0ba..39c68ddf 100644
--- a/bin/domain/imag-contact/src/main.rs
+++ b/bin/domain/imag-contact/src/main.rs
@@ -73,7 +73,6 @@ use libimagerror::iter::TraceIterator;
use libimagcontact::store::ContactStore;
use libimagcontact::contact::Contact;
use libimagcontact::deser::DeserVcard;
-use libimagstore::iter::get::StoreIdGetIteratorExtension;
mod ui;
mod util;
@@ -120,7 +119,7 @@ fn list(rt: &Runtime) {
.store()
.all_contacts()
.map_err_trace_exit_unwrap()
- .into_get_iter(rt.store())
+ .into_get_iter()
.trace_unwrap_exit()
.map(|fle| fle.ok_or_else(|| Error::from(err_msg("StoreId not found".to_owned()))))
.trace_unwrap_exit()
@@ -206,7 +205,7 @@ fn show(rt: &Runtime) {
rt.store()
.all_contacts()
.map_err_trace_exit_unwrap()
- .into_get_iter(rt.store())
+ .into_get_iter()
.trace_unwrap_exit()
.map(|o| o.unwrap_or_else(|| {
error!("Failed to get entry");
@@ -257,7 +256,7 @@ fn find(rt: &Runtime) {
.store()
.all_contacts()
.map_err_trace_exit_unwrap()
- .into_get_iter(rt.store())
+ .into_get_iter()
.map(|el| {
el.map_err_trace_exit_unwrap()
.ok_or_else(|| {
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs
index 8fb59022..4f2a485f 100644
--- a/lib/core/libimagrt/src/runtime.rs
+++ b/lib/core/libimagrt/src/runtime.rs
@@ -22,7 +22,6 @@ use std::process::Command;
use std::env;
use std::process::exit;
use std::io::Stdin;
-use std::sync::Arc;
use std::io::StdoutLock;
use std::borrow::Borrow;
use std::result::Result as RResult;
@@ -48,7 +47,6 @@ use libimagerror::trace::*;
use libimagerror::io::ToExitCode;
use libimagstore::store::Store;
use libimagstore::storeid::StoreId;
-use libimagstore::file_abstraction::InMemoryFileAbstraction;
use libimagutil::debug_result::DebugResult;
use spec::CliSpec;
use atty;
@@ -143,9 +141,7 @@ impl<'a> Runtime<'a> {
trace!("Config = {:#?}", config);
let store_result = if cli_app.use_inmemory_fs() {
- Store::new_with_backend(storepath,
- &config,
- Arc::new(InMemoryFileAbstraction::default()))
+ Store::new_inmemory(storepath, &config)
} else {
Store::new(storepath, &config)
};
@@ -418,7 +414,7 @@ impl<'a> Runtime<'a> {
trace!("Got IDs = {}", buf);
buf.lines()
.map(PathBuf::from)
- .map(|id| StoreId::new_baseless(id).map_err(Error::from))
+ .map(|id| StoreId::new(id).map_err(Error::from))
.collect()
})
} else {
diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs
index f68d2aa1..f6264337 100644
--- a/lib/core/libimagstore/src/file_abstraction/fs.rs
+++ b/lib/core/libimagstore/src/file_abstraction/fs.rs
@@ -28,7 +28,7 @@ use super::FileAbstraction;
use super::FileAbstractionInstance;
use super::Drain;
use store::Entry;
-use storeid::StoreId;
+use storeid::StoreIdWithBase;
use file_abstraction::iter::PathIterator;
use file_abstraction::iter::PathIterBuilder;
@@ -45,7 +45,7 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
/**
* Get the content behind this file
*/
- fn get_file_content(&mut self, id: StoreId) -> Result<Option<Entry>> {
+ fn get_file_content<'a>(&mut self, id: StoreIdWithBase<'a>) -> Result<Option<Entry>> {
debug!("Getting lazy file: {:?}", self);
let mut file = match open_file(&self.0) {
@@ -153,18 +153,18 @@ impl FileAbstraction for FSFileAbstraction {
})
}
- fn pathes_recursively(&self,
+ fn pathes_recursively<'a>(&self,
basepath: PathBuf,
- storepath: PathBuf,
+ storepath: &'a PathBuf,
backend: Arc<FileAbstraction>)
- -> Result<PathIterator>
+ -> Result<PathIterator<'a>>
{
trace!("Building PathIterator object");
Ok(PathIterator::new(Box::new(WalkDirPathIterBuilder { basepath }), storepath, backend))
}
}
-pub(crate) struct WalkDirPathIterBuilder {
+pub struct WalkDirPathIterBuilder {
basepath: PathBuf
}
diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
index 292aea15..43dddb0c 100644
--- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs
+++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
@@ -33,7 +33,7 @@ use super::FileAbstraction;
use super::FileAbstractionInstance;
use super::Drain;
use store::Entry;
-use storeid::StoreId;
+use storeid::StoreIdWithBase;
use file_abstraction::iter::PathIterator;
use file_abstraction::iter::PathIterBuilder;
@@ -64,7 +64,7 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
/**
* Get the mutable file behind a InMemoryFileAbstraction object
*/
- fn get_file_content(&mut self, _: StoreId) -> Result<Option<Entry>> {
+ fn get_file_content(&mut self, _: StoreIdWithBase<'_>) -> Result<Option<Entry>> {
debug!("Getting lazy file: {:?}", self);
self.fs_abstraction
@@ -187,7 +187,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
Ok(())
}
- fn pathes_recursively(&self, _basepath: PathBuf, storepath: PathBuf, backend: Arc<FileAbstraction>) -> Result<PathIterator> {
+ fn pathes_recursively<'a>(&self, _basepath: PathBuf, storepath: &'a PathBuf, backend: Arc<FileAbstraction>) -> Result<PathIterator<'a>> {
trace!("Building PathIterator object (inmemory implementation)");
let keys : Vec<PathBuf> = self
.backend()
@@ -203,7 +203,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
}
}
-pub(crate) struct InMemPathIterBuilder(Vec<PathBuf>);
+pub struct InMemPathIterBuilder(Vec<PathBuf>);
impl PathIterBuilder for InMemPathIterBuilder {
fn build_iter(&self) -> Box<Iterator<Item = Result<PathBuf>>> {
diff --git a/lib/core/libimagstore/src/file_abstraction/iter.rs b/lib/core/libimagstore/src/file_abstraction/iter.rs
index 9df59a2f..2eda4c27 100644
--- a/lib/core/libimagstore/src/file_abstraction/iter.rs
+++ b/lib/core/libimagstore/src/file_abstraction/iter.rs
@@ -22,11 +22,11 @@ use std::sync::Arc;
use failure::Fallible as Result;
-use storeid::StoreId;
+use storeid::StoreIdWithBase;
use file_abstraction::FileAbstraction;
/// See documentation for PathIterator
-pub trait PathIterBuilder {
+pub(crate) trait PathIterBuilder {
fn build_iter(&self) -> Box<Iterator<Item = Result<PathBuf>>>;
fn in_collection(&mut self, c: &str);
}
@@ -45,19 +45,19 @@ pub trait PathIterBuilder {
///
/// This means quite a few allocations down the road, as the PathIterator itself is not generic, but
/// this seems to be the best way to implement this.
-pub struct PathIterator {
+pub(crate) struct PathIterator<'a> {
iter_builder: Box<PathIterBuilder>,
iter: Box<Iterator<Item = Result<PathBuf>>>,
- storepath: PathBuf,
+ storepath: &'a PathBuf,
backend: Arc<FileAbstraction>,
}
-impl PathIterator {
+impl<'a> PathIterator<'a> {
pub fn new(iter_builder: Box<PathIterBuilder>,
- storepath: PathBuf,
+ storepath: &'a PathBuf,
backend: Arc<FileAbstraction>)
- -> PathIterator
+ -> PathIterator<'a>
{
trace!("Generating iterator object with PathIterBuilder");
let iter = iter_builder.build_iter();
@@ -71,10 +71,22 @@ impl PathIterator {
self
}
+ /// Turn iterator into its internals
+ ///
+ /// Used for `Entries::into_storeid_iter()`
+ ///
+ /// # TODO
+ ///
+ /// Revisit whether this can be done in a cleaner way. See commit message for why this is
+ /// needed.
+ pub(crate) fn into_inner(self) -> Box<Iterator<Item = Result<PathBuf>>> {
+ self.iter
+ }
+
}
-impl Iterator for PathIterator {
- type Item = Result<StoreId>;
+impl<'a> Iterator for PathIterator<'a> {
+ type Item = Result<StoreIdWithBase<'a>>;
fn next(&mut self) -> Option<Self::Item> {
while let Some(next) = self.iter.next() {
@@ -82,7 +94,7 @@ impl Iterator for PathIterator {
Err(e) => return Some(Err(e)),
Ok(next) => match self.backend.is_file(&next) {
Err(e) => return Some(Err(e)),
- Ok(true) => return Some(StoreId::from_full_path(&self.storepath, next)),
+ Ok(true) => return Some(StoreIdWithBase::from_full_path(&self.storepath, next)),
Ok(false) => { continue },
}
}
diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs
index d7716a56..9a80293e 100644
--- a/lib/core/libimagstore/src/file_abstraction/mod.rs
+++ b/lib/core/libimagstore/src/file_abstraction/mod.rs
@@ -25,20 +25,16 @@ use std::sync::Arc;
use failure::Fallible as Result;
use store::Entry;
-use storeid::StoreId;
+use storeid::StoreIdWithBase;
-mod fs;
-mod inmemory;
-pub(crate) mod iter;
+pub mod fs;
+pub mod inmemory;
+pub mod iter;
-pub use self::fs::FSFileAbstraction;
-pub use self::fs::FSFileAbstractionInstance;
-pub use self::inmemory::InMemoryFileAbstraction;
-pub use self::inmemory::InMemoryFileAbstractionInstance;
use self::iter::PathIterator;
/// An abstraction trait over filesystem actions
-pub trait FileAbstraction : Debug {
+pub(crate) trait FileAbstraction : Debug {
fn remove_file(&self, path: &PathBuf) -> Result<()>;
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<()>;
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<()>;
@@ -52,17 +48,17 @@ pub trait FileAbstraction : Debug {
fn drain(&self) -> Result<Drain>;
fn fill<'a>(&'a mut self, d: Drain) -> Result<()>;
- fn pathes_recursively(&self, basepath: PathBuf, storepath: PathBuf, backend: Arc<FileAbstraction>) -> Result<PathIterator>;
+ fn pathes_recursively<'a>(&self, basepath: PathBuf, storepath: &'a PathBuf, backend: Arc<FileAbstraction>) -> Result<PathIterator<'a>>;
}
/// An abstraction trait over actions on files
-pub trait FileAbstractionInstance : Debug {
+pub(crate) trait FileAbstractionInstance : Debug {
/// Get the contents of the FileAbstractionInstance, as Entry object.
///
- /// The `StoreId` is passed because the backend does not know where the Entry lives, but the
+ /// The `StoreIdWithBase` is passed because the backend does not know where the Entry lives, but the
/// Entry type itself must be constructed with the id.
- fn get_file_content(&mut self, id: StoreId) -> Result<Option<Entry>>;
+ fn get_file_content<'a>(&mut self, id: StoreIdWithBase<'a>) -> Result<Option<Entry>>;
fn write_file_content(&mut self, buf: &Entry) -> Result<()>;
}
@@ -101,18 +97,19 @@ mod test {
use super::FileAbstractionInstance;
use super::inmemory::InMemoryFileAbstraction;
use super::inmemory::InMemoryFileAbstractionInstance;
- use storeid::StoreId;
+ use storeid::StoreIdWithBase;
use store::Entry;
#[test]
fn lazy_file() {
+ let store_path = PathBuf::from("/");
let fs = InMemoryFileAbstraction::default();
let mut path = PathBuf::from("tests");
path.set_file_name("test1");
let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
- let loca = StoreId::new_baseless(path).unwrap();
+ let loca = StoreIdWithBase::new(&store_path, path);
let file = Entry::from_str(loca.clone(), &format!(r#"---
[imag]
version = "{}"
@@ -126,13 +123,14 @@ Hello World"#, env!("CARGO_PKG_VERSION"))).unwrap();
#[test]
fn lazy_file_multiline() {
+ let store_path = PathBuf::from("/");
let fs = InMemoryFileAbstraction::default();
let mut path = PathBuf::from("tests");
path.set_file_name("test1");
let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
- let loca = StoreId::new_baseless(path).unwrap();
+ let loca = StoreIdWithBase::new(&store_path, path);
let file = Entry::from_str(loca.clone(), &format!(r#"---
[imag]
version = "{}"
@@ -147,13 +145,14 @@ baz"#, env!("CARGO_PKG_VERSION"))).unwrap();
#[test]
fn lazy_file_multiline_trailing_newlines() {
+ let store_path = PathBuf::from("/");
let fs = InMemoryFileAbstraction::default();
let mut path = PathBuf::from("tests");
path.set_file_name("test1");
let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
- let loca = StoreId::new_baseless(path).unwrap();
+ let loca = StoreIdWithBase::new(&store_path, path);
let file = Entry::from_str(loca.clone(), &format!(r#"---
[imag]
version = "{}"
diff --git a/lib/core/libimagstore/src/iter.rs b/lib/core/libimagstore/src/iter.rs
index 1639b02c..2e895b78 100644
--- a/lib/core/libimagstore/src/iter.rs
+++ b/lib/core/libimagstore/src/iter.rs
@@ -167,11 +167,11 @@ use failure::Fallible as Result;
///
/// Functionality to exclude subdirectories is not possible with the current implementation and has
/// to be done during iteration, with filtering (as usual).
-pub struct Entries<'a>(PathIterator, &'a Store);
+pub struct Entries<'a>(PathIterator<'a>, &'a Store);
impl<'a> Entries<'a> {
- pub(crate) fn new(pi: PathIterator, store: &'a Store) -> Self {
+ pub(crate) fn new(pi: PathIterator<'a>, store: &'a Store) -> Self {
Entries(pi, store)
}
@@ -179,29 +179,38 @@ impl<'a> Entries<'a> {
Entries(self.0.in_collection(c), self.1)
}
- pub fn without_store(self) -> StoreIdIterator {
- StoreIdIterator::new(Box::new(self.0))
+ /// Turn `Entries` iterator into generic `StoreIdIterator`
+ ///
+ /// # TODO
+ ///
+ /// Revisit whether this can be done in a cleaner way. See commit message for why this is
+ /// needed.
+ pub fn into_storeid_iter(self) -> StoreIdIterator {
+ let iter = self.0
+ .into_inner()
+ .map(|r| r.and_then(StoreId::new));
+ StoreIdIterator::new(Box::new(iter))
}
/// Transform the iterator into a StoreDeleteIterator
///
/// This immitates the API from `libimagstore::iter`.
<