Merge branch 'fixes'

This commit is contained in:
Matthias Beyer 2018-10-09 17:38:05 +02:00
commit 3c801a264d
4 changed files with 35 additions and 20 deletions

View file

@ -394,7 +394,7 @@ mod tests {
#[test] #[test]
fn test_link_modificates() { fn test_link_modificates() {
setup_logging(); setup_logging();
let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) let rt = generate_test_runtime(vec!["test1", "test2"])
.unwrap(); .unwrap();
debug!("Runtime created"); debug!("Runtime created");
@ -423,7 +423,7 @@ mod tests {
#[test] #[test]
fn test_linking_links() { fn test_linking_links() {
setup_logging(); setup_logging();
let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) let rt = generate_test_runtime(vec!["test1", "test2"])
.unwrap(); .unwrap();
debug!("Runtime created"); debug!("Runtime created");
@ -452,7 +452,7 @@ mod tests {
#[test] #[test]
fn test_multilinking() { fn test_multilinking() {
setup_logging(); setup_logging();
let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) let rt = generate_test_runtime(vec!["test1", "test2"])
.unwrap(); .unwrap();
debug!("Runtime created"); debug!("Runtime created");
@ -482,7 +482,7 @@ mod tests {
#[test] #[test]
fn test_linking_more_than_two() { fn test_linking_more_than_two() {
setup_logging(); setup_logging();
let rt = generate_test_runtime(vec!["internal", "test1", "test2", "test3"]) let rt = generate_test_runtime(vec!["test1", "test2", "test3"])
.unwrap(); .unwrap();
debug!("Runtime created"); debug!("Runtime created");
@ -519,7 +519,7 @@ mod tests {
#[test] #[test]
fn test_linking_links_unlinking_removes_links() { fn test_linking_links_unlinking_removes_links() {
setup_logging(); setup_logging();
let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) let rt = generate_test_runtime(vec!["test1", "test2"])
.unwrap(); .unwrap();
debug!("Runtime created"); debug!("Runtime created");
@ -555,7 +555,7 @@ mod tests {
#[test] #[test]
fn test_linking_and_unlinking_more_than_two() { fn test_linking_and_unlinking_more_than_two() {
setup_logging(); setup_logging();
let rt = generate_test_runtime(vec!["internal", "test1", "test2", "test3"]) let rt = generate_test_runtime(vec!["test1", "test2", "test3"])
.unwrap(); .unwrap();
debug!("Runtime created"); debug!("Runtime created");

View file

@ -137,7 +137,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let mut mtx = self.backend().lock().expect("Locking Mutex failed"); let mut mtx = self.backend().lock().expect("Locking Mutex failed");
let backend = mtx.get_mut(); let backend = mtx.get_mut();
let a = backend.get(from).cloned().ok_or_else(|| SE::from_kind(SEK::FileNotFound))?; let a = backend.remove(from).ok_or_else(|| SE::from_kind(SEK::FileNotFound))?;
backend.insert(to.clone(), a); backend.insert(to.clone(), a);
debug!("Renaming: {:?} -> {:?} worked", from, to); debug!("Renaming: {:?} -> {:?} worked", from, to);
Ok(()) Ok(())

View file

@ -229,10 +229,16 @@ impl Store {
debug!("Creating id: '{}'", id); debug!("Creating id: '{}'", id);
let exists = id.exists()? || self.entries let exists = self.entries
.read() .read()
.map(|map| map.contains_key(&id))
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.map(|map| map.contains_key(&id))
.and_then(|exists| if exists {
Ok(exists)
} else {
let pb = id.clone().into_pathbuf().map_err(SE::from)?;
self.backend.exists(&pb)
})
.chain_err(|| SEK::CreateCallError(id.clone()))?; .chain_err(|| SEK::CreateCallError(id.clone()))?;
if exists { if exists {
@ -314,10 +320,16 @@ impl Store {
debug!("Getting id: '{}'", id); debug!("Getting id: '{}'", id);
let exists = id.exists()? || self.entries let exists = self.entries
.read() .read()
.map(|map| map.contains_key(&id))
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.map(|map| map.contains_key(&id))
.and_then(|exists| if exists {
Ok(exists)
} else {
let pb = id.clone().into_pathbuf().map_err(SE::from)?;
self.backend.exists(&pb)
})
.chain_err(|| SEK::GetCallError(id.clone()))?; .chain_err(|| SEK::GetCallError(id.clone()))?;
if !exists { if !exists {
@ -461,12 +473,7 @@ impl Store {
debug!("Deleting id: '{}'", id); debug!("Deleting id: '{}'", id);
// Small optimization: We need the pathbuf for deleting, but when calling
// 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().into_pathbuf()?;
{ {
let mut entries = self let mut entries = self
.entries .entries
@ -1183,8 +1190,8 @@ mod store_tests {
assert!(store.create(id.clone()).is_ok()); assert!(store.create(id.clone()).is_ok());
} }
{
let id_with_base = id.clone().with_base(store.path().clone()); let id_with_base = id.clone().with_base(store.path().clone());
{
assert!(store.entries.read().unwrap().get(&id_with_base).is_some()); assert!(store.entries.read().unwrap().get(&id_with_base).is_some());
} }
@ -1196,8 +1203,16 @@ mod store_tests {
assert!(store.entries.read().unwrap().get(&id_mv_with_base).is_some()); assert!(store.entries.read().unwrap().get(&id_mv_with_base).is_some());
} }
assert!(match store.get(id.clone()) { Ok(None) => true, _ => false }, {
"Moved id ({:?}) is still there", id); let pb = id_with_base.into_pathbuf().unwrap();
let exists = store.backend.exists(&pb).unwrap();
assert!(!exists, "Old entry exists in Filesystem, but shouldn't");
}
let result = store.get(id.clone());
assert!(match result { Ok(None) => true, _ => false },
"Moved id ({:?}) is still there: {:?}", id, result);
assert!(match store.get(id_mv.clone()) { Ok(Some(_)) => true, _ => false }, assert!(match store.get(id_mv.clone()) { Ok(Some(_)) => true, _ => false },
"New id ({:?}) is not in store...", id_mv); "New id ({:?}) is not in store...", id_mv);
} }

View file

@ -96,7 +96,7 @@ macro_rules! make_mock_app {
#[allow(unused)] #[allow(unused)]
pub fn generate_test_runtime<'a>(mut args: Vec<&'static str>) -> Result<Runtime<'a>, RuntimeError> { pub fn generate_test_runtime<'a>(mut args: Vec<&'static str>) -> Result<Runtime<'a>, RuntimeError> {
let mut cli_args = vec![$appname, "--rtp", "/tmp"]; let mut cli_args = vec![$appname];
cli_args.append(&mut args); cli_args.append(&mut args);