diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-02-15 22:15:58 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-02-15 22:15:58 +0100 |
commit | a6ad19a14f16c5344ea65df3efcc00464b2ad9aa (patch) | |
tree | 2d84c1a8021fe8b16faf6ef75e0b4a0b24cba8d0 /lib | |
parent | 08b7a46c74c37d7179d7b9332e8e165faa056ffc (diff) | |
parent | 6fd2c9b958ec17e5eb4bcfc365df126a89540bce (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>
Diffstat (limited to 'lib')
29 files changed, 262 insertions, 378 deletions
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`. pub fn into_delete_iter(self) -> StoreDeleteIterator<'a> { - StoreDeleteIterator::new(Box::new(self.0), self.1) + StoreDeleteIterator::new(Box::new(self.0.map(|r| r.map(|id| id.without_base()))), self.1) } /// Transform the iterator into a StoreGetIterator /// /// This immitates the API from `libimagstore::iter`. pub fn into_get_iter(self) -> StoreGetIterator<'a> { - StoreGetIterator::new(Box::new(self.0), self.1) + StoreGetIterator::new(Box::new(self.0.map(|r| r.map(|id| id.without_base()))), self.1) } /// Transform the iterator into a StoreRetrieveIterator /// /// This immitates the API from `libimagstore::iter`. pub fn into_retrieve_iter(self) -> StoreRetrieveIterator<'a> { - StoreRetrieveIterator::new(Box::new(self.0), self.1) + StoreRetrieveIterator::new(Box::new(self.0.map(|r| r.map(|id| id.without_base()))), self.1) } } @@ -210,7 +219,7 @@ impl<'a> Iterator for Entries<'a> { type Item = Result<StoreId>; fn next(&mut self) -> Option<Self::Item> { - self.0.next() + self.0.next().map(|r| r.map(|id| id.without_base())) } } @@ -227,7 +236,7 @@ mod tests { use store::Store; use storeid::StoreId; - use file_abstraction::InMemoryFileAbstraction; + use file_abstraction::inmemory::InMemoryFileAbstraction; use libimagutil::variants::generate_variants; pub fn get_store() -> Store { @@ -244,7 +253,7 @@ mod tests { let base = String::from("entry"); let variants = vec!["coll_1", "coll_2", "coll_3"]; let modifier = |base: &String, v: &&str| { - StoreId::new(Some(store.path().clone()), PathBuf::from(format!("{}/{}", *v, base))).unwrap() + StoreId::new(PathBuf::from(format!("{}/{}", *v, base))).unwrap() }; generate_variants(&base, variants.iter(), &modifier) diff --git a/lib/core/libimagstore/src/lib.rs b/lib/core/libimagstore/src/lib.rs index fe721daa..c3274f6b 100644 --- a/lib/core/libimagstore/src/lib.rs +++ b/lib/core/libimagstore/src/lib.rs @@ -58,5 +58,5 @@ pub mod storeid; pub mod iter; pub mod store; mod configuration; -pub mod file_abstraction; +mod file_abstraction; diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index aa3ae4ba..3cd0bfeb 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -43,12 +43,10 @@ use failure::Error; use storeid::{IntoStoreId, StoreId}; use iter::Entries; +use file_abstraction::FileAbstraction; use file_abstraction::FileAbstractionInstance; - -// We re-export the following things so tests can use them -pub use file_abstraction::FileAbstraction; -pub use file_abstraction::FSFileAbstraction; -pub use file_abstraction::InMemoryFileAbstraction; +use file_abstraction::fs::FSFileAbstraction; +use file_abstraction::inmemory::InMemoryFileAbstraction; use libimagutil::debug_result::*; @@ -64,14 +62,15 @@ enum StoreEntryStatus { #[derive(Debug)] struct StoreEntry { id: StoreId, + store_base: PathBuf, // small sacrefice over lifetimes on the Store type file: Box<FileAbstractionInstance>, status: StoreEntryStatus, } impl StoreEntry { - fn new(id: StoreId, backend: &Arc<FileAbstraction>) -> Result<StoreEntry> { - let pb = id.clone().into_pathbuf()?; + fn new(store_base: PathBuf, id: StoreId, backend: &Arc<FileAbstraction>) -> Result<StoreEntry> { + let pb = id.clone().with_base(&store_base).into_pathbuf()?; #[cfg(feature = "fs-lock")] { @@ -82,6 +81,7 @@ impl StoreEntry { Ok(StoreEntry { id, + store_base, file: backend.new_instance(pb), status: StoreEntryStatus::Present, }) @@ -95,7 +95,7 @@ impl StoreEntry { fn get_entry(&mut self) -> Result<Entry> { if !self.is_borrowed() { - match self.file.get_file_content(self.id.clone())? { + match self.file.get_file_content(self.id.clone().with_base(&self.store_base))? { Some(file) => Ok(file), None => Ok(Entry::new(self.id.clone())) } @@ -170,13 +170,24 @@ impl Store { Store::new_with_backend(location, store_config, backend) } + /// Create the store with an in-memory filesystem + /// + /// # Usage + /// + /// this is for testing purposes only + #[inline] + pub fn new_inmemory(location: PathBuf, store_config: &Option<Value>) -> Result<Store> { + let backend = Arc::new(InMemoryFileAbstraction::default()); + Self::new_with_backend(location, store_config, backend) + } + /// Create a Store object as descripbed in `Store::new()` documentation, but with an alternative /// backend implementation. /// /// Do not use directly, only for testing purposes. - pub fn new_with_backend(location: PathBuf, - store_config: &Option<Value>, - backend: Arc<FileAbstraction>) -> Result<Store> { + pub(crate) fn new_with_backend(location: PathBuf, + store_config: &Option<Value>, + backend: Arc<FileAbstraction>) -> Result<Store> { use configuration::*; debug!("Building new Store object"); @@ -218,7 +229,7 @@ impl Store { /// On success: FileLockEntry /// pub fn create<'a, S: IntoStoreId>(&'a self, id: S) -> Result<FileLockEntry<'a>> { - let id = id.into_storeid()?.with_base(self.path().clone()); + let id = id.into_storeid()?; debug!("Creating id: '{}'", id); @@ -244,7 +255,7 @@ impl Store { } hsmap.insert(id.clone(), { debug!("Creating: '{}'", id); - let mut se = StoreEntry::new(id.clone(), &self.backend)?; + let mut se = StoreEntry::new(self.path().clone(), id.clone(), &self.backend)?; se.status = StoreEntryStatus::Borrowed; se }); @@ -266,14 +277,14 @@ impl Store { /// On success: FileLockEntry /// pub fn retrieve<'a, S: IntoStoreId>(&'a self, id: S) -> Result<FileLockEntry<'a>> { - let id = id.into_storeid()?.with_base(self.path().clone()); + let id = id.into_storeid()?; debug!("Retrieving id: '{}'", id); let entry = self .entries .write() .map_err(|_| Error::from(EM::LockError)) .and_then(|mut es| { - let new_se = StoreEntry::new(id.clone(), &self.backend)?; + let new_se = StoreEntry::new(self.path().clone(), id.clone(), &self.backend)?; let se = es.entry(id.clone()).or_insert(new_se); let entry = se.get_entry(); se.status = StoreEntryStatus::Borrowed; @@ -296,7 +307,7 @@ impl Store { /// - Errors Store::retrieve() might return /// pub fn get<'a, S: IntoStoreId + Clone>(&'a self, id: S) -> Result<Option<FileLockEntry<'a>>> { - let id = id.into_storeid()?.with_base(self.path().clone()); + let id = id.into_storeid()?; debug!("Getting id: '{}'", id); @@ -409,7 +420,7 @@ impl Store { /// On success: Entry /// pub fn get_copy<S: IntoStoreId>(&self, id: S) -> Result<Entry> { - let id = id.into_storeid()?.with_base(self.path().clone()); + let id = id.into_storeid()?; debug!("Retrieving copy of '{}'", id); let entries = self.entries.write() .map_err(|_| Error::from(EM::LockError)) @@ -422,7 +433,7 @@ impl Store { .map_err(Error::from) } - StoreEntry::new(id, &self.backend)?.get_entry() + StoreEntry::new(self.path().clone(), id, &self.backend)?.get_entry() } /// Delete an entry and the corrosponding file on disk @@ -432,7 +443,7 @@ impl Store { /// On success: () /// pub fn delete<S: IntoStoreId>(&self, id: S) -> Result<()> { - let id = id.into_storeid()?.with_base(self.path().clone()); + let id = id.into_storeid()?; debug!("Deleting id: '{}'", id); @@ -440,7 +451,7 @@ impl Store { // StoreId::exists(), a PathBuf object gets allocated. So we simply get a // PathBuf here, check whether it is there and if it is, we can re-use it to // delete the filesystem file. - let pb = id.clone().into_pathbuf()?; + let pb = id.clone().with_base(self.path()).into_pathbuf()?; { let mut entries = self @@ -507,7 +518,6 @@ impl Store { fn save_to_other_location(&self, entry: &FileLockEntry, new_id: StoreId, remove_old: bool) -> Result<()> { - let new_id = new_id.with_base(self.path().clone()); let hsmap = self .entries .write() @@ -522,8 +532,8 @@ impl Store { let old_id = entry.get_location().clone(); - let old_id_as_path = old_id.clone().with_base(self.path().clone()).into_pathbuf()?; - let new_id_as_path = new_id.clone().with_base(self.path().clone()).into_pathbuf()?; + let old_id_as_path = old_id.clone().with_base(self.path()).into_pathbuf()?; + let new_id_as_path = new_id.clone().with_base(self.path()).into_pathbuf()?; self.backend .copy(&old_id_as_path, &new_id_as_path) .and_then(|_| if remove_old { @@ -571,9 +581,6 @@ impl Store { /// So the link is _partly dangling_, so to say. /// pub fn move_by_id(&self, old_id: StoreId, new_id: StoreId) -> Result<()> { - let new_id = new_id.with_base(self.path().clone()); - let old_id = old_id.with_base(self.path().clone()); - debug!("Moving '{}' to '{}'", old_id, new_id); { @@ -594,8 +601,8 @@ impl Store { debug!("Old id is not yet borrowed"); - let old_id_pb = old_id.clone().with_base(self.path().clone()).into_pathbuf()?; - let new_id_pb = new_id.clone().with_base(self.path().clone()).into_pathbuf()?; + let old_id_pb = old_id.clone().with_base(self.path()).into_pathbuf()?; + let new_id_pb = new_id.clone().with_base(self.path()).into_pathbuf()?; if self.backend.exists(&new_id_pb)? { return Err(format_err!("Entry already exists: {}", new_id)); @@ -618,8 +625,8 @@ impl Store { assert!(hsmap .remove(&old_id) .and_then(|mut entry| { - entry.id = new_id.clone(); - hsmap.insert(new_id.clone(), entry) + entry.id = new_id.clone().into(); + hsmap.insert(new_id.clone().into(), entry) }).is_none()) } @@ -631,7 +638,7 @@ impl Store { pub fn entries<'a>(&'a self) -> Result<Entries<'a>> { trace!("Building 'Entries' iterator"); self.backend - .pathes_recursively(self.path().clone(), self.path().clone(), self.backend.clone()) + .pathes_recursively(self.path().clone(), self.path(), self.backend.clone()) .map(|i| Entries::new(i, self)) } @@ -645,7 +652,7 @@ impl Store { .context(format_err!("CreateCallError: {}", id)); let backend_has_entry = |id: StoreId| - self.backend.exists(&id.with_base(self.path().to_path_buf()).into_pathbuf()?); + self.backend.exists(&id.with_base(self.path()).into_pathbuf()?); Ok(cache_has_entry(&id)? || backend_has_entry(id)?) } @@ -1000,7 +1007,7 @@ Hai setup_logging(); debug!("{}", TEST_ENTRY); - let entry = Entry::from_str(StoreId::new_baseless(PathBuf::from("test/foo~1.3")).unwrap(), + let entry = Entry::from_str(StoreId::new(PathBuf::from("test/foo~1.3")).unwrap(), TEST_ENTRY).unwrap(); assert_eq!(entry.content, "Hai"); @@ -1014,7 +1021,7 @@ Hai setup_logging(); debug!("{}", TEST_ENTRY); - let entry = Entry::from_str(StoreId::new_baseless(PathBuf::from("test/foo~1.3")).unwrap(), + let entry = Entry::from_str(StoreId::new(PathBuf::from("test/foo~1.3")).unwrap(), TEST_ENTRY).unwrap(); let string = entry.to_str().unwrap(); @@ -1029,7 +1036,7 @@ Hai setup_logging(); debug!("{}", TEST_ENTRY_TNL); - let entry = Entry::from_str(StoreId::new_baseless(PathBuf::from("test/foo~1.3")).unwrap(), + let entry = Entry::from_str(StoreId::new(PathBuf::from("test/foo~1.3")).unwrap(), TEST_ENTRY_TNL).unwrap(); let string = entry.to_str().unwrap(); @@ -1049,9 +1056,9 @@ mod store_tests { } use super::Store; - use file_abstraction::InMemoryFileAbstraction; pub fn get_store() -> Store { + use file_abstraction::inmemory::InMemoryFileAbstraction; let backend = Arc::new(InMemoryFileAbstraction::default()); Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap() } @@ -1072,7 +1079,7 @@ mod store_tests { let s = format!("test-{}", n); let entry = store.create(PathBuf::from(s.clone())).unwrap(); assert!(entry.verify().is_ok()); - let loc = entry.get_location().clone().into_pathbuf().unwrap(); + let loc = entry.get_location().clone().with_base(store.path()).into_pathbuf().unwrap(); assert!(loc.starts_with("/")); assert!(loc.ends_with(s)); } @@ -1093,7 +1100,7 @@ mod store_tests { assert!(entry.verify().is_ok()); - let loc = entry.get_location().clone().into_pathbuf().unwrap(); + let l |