summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-10-13 15:31:17 +0200
committerGitHub <noreply@github.com>2017-10-13 15:31:17 +0200
commit935701955133f7b42f30ded96b04d6bcbb2b4ab7 (patch)
tree1b37559abfdaeb2b95746012e6c06010c27355ff
parentb83367f383129ef2ead70a6d9c9dcabfbf889c69 (diff)
parent23f4d7948fe0623324c312247212ac805f70fc20 (diff)
downloadimag-935701955133f7b42f30ded96b04d6bcbb2b4ab7.zip
imag-935701955133f7b42f30ded96b04d6bcbb2b4ab7.tar.gz
Merge pull request #1138 from matthiasbeyer/libimagstore/entries-do-not-yield-dirs
Fix Store::entries() to not yield directories
-rw-r--r--doc/src/09020-changelog.md4
-rw-r--r--lib/core/libimagstore/src/file_abstraction/fs.rs4
-rw-r--r--lib/core/libimagstore/src/file_abstraction/inmemory.rs7
-rw-r--r--lib/core/libimagstore/src/file_abstraction/mod.rs1
-rw-r--r--lib/core/libimagstore/src/file_abstraction/stdio/mod.rs4
-rw-r--r--lib/core/libimagstore/src/file_abstraction/stdio/out.rs4
-rw-r--r--lib/core/libimagstore/src/store.rs26
7 files changed, 39 insertions, 11 deletions
diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md
index 7f4aace..85cdd77 100644
--- a/doc/src/09020-changelog.md
+++ b/doc/src/09020-changelog.md
@@ -34,6 +34,10 @@ This section contains the changelog from the last release to the next release.
anymore. This is minor because `libimagentryanntation` is not yet used by
any other crate.
+* Bugfixes
+ * `Store::entries()` does not yield StoreIds which point to directories
+ anymore, only StoreIds pointing to files.
+
## 0.4.0
* Major changes
diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs
index de29292..0773a17 100644
--- a/lib/core/libimagstore/src/file_abstraction/fs.rs
+++ b/lib/core/libimagstore/src/file_abstraction/fs.rs
@@ -150,6 +150,10 @@ impl FileAbstraction for FSFileAbstraction {
Ok(path.exists())
}
+ fn is_file(&self, path: &PathBuf) -> Result<bool, SE> {
+ Ok(path.is_file())
+ }
+
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance> {
Box::new(FSFileAbstractionInstance::Absent(p))
}
diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
index 909aad9..9a9adf6 100644
--- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs
+++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
@@ -159,6 +159,13 @@ impl FileAbstraction for InMemoryFileAbstraction {
Ok(backend.contains_key(pb))
}
+ fn is_file(&self, pb: &PathBuf) -> Result<bool, SE> {
+ // Because we only store Entries in the memory-internal backend, we only have to check for
+ // existance here, as if a path exists in the inmemory storage, it is always mapped to an
+ // entry. hence it is always a path to a file
+ self.exists(pb)
+ }
+
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance> {
Box::new(InMemoryFileAbstractionInstance::new(self.backend().clone(), p))
}
diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs
index 4aad4df..6c23f34 100644
--- a/lib/core/libimagstore/src/file_abstraction/mod.rs
+++ b/lib/core/libimagstore/src/file_abstraction/mod.rs
@@ -44,6 +44,7 @@ pub trait FileAbstraction : Debug {
fn create_dir_all(&self, _: &PathBuf) -> Result<(), SE>;
fn exists(&self, &PathBuf) -> Result<bool, SE>;
+ fn is_file(&self, &PathBuf) -> Result<bool, SE>;
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance>;
diff --git a/lib/core/libimagstore/src/file_abstraction/stdio/mod.rs b/lib/core/libimagstore/src/file_abstraction/stdio/mod.rs
index a9606c9..7bf4f42 100644
--- a/lib/core/libimagstore/src/file_abstraction/stdio/mod.rs
+++ b/lib/core/libimagstore/src/file_abstraction/stdio/mod.rs
@@ -119,6 +119,10 @@ impl<W: Write, M: Mapper> FileAbstraction for StdIoFileAbstraction<W, M> {
self.0.exists(p)
}
+ fn is_file(&self, p: &PathBuf) -> Result<bool, SE> {
+ self.0.is_file(p)
+ }
+
fn drain(&self) -> Result<Drain, SE> {
self.0.drain()
}
diff --git a/lib/core/libimagstore/src/file_abstraction/stdio/out.rs b/lib/core/libimagstore/src/file_abstraction/stdio/out.rs
index 456fe9d..c8540b3 100644
--- a/lib/core/libimagstore/src/file_abstraction/stdio/out.rs
+++ b/lib/core/libimagstore/src/file_abstraction/stdio/out.rs
@@ -140,6 +140,10 @@ impl<W: Write, M: Mapper> FileAbstraction for StdoutFileAbstraction<W, M> {
self.mem.exists(p)
}
+ fn is_file(&self, p: &PathBuf) -> Result<bool, SE> {
+ self.mem.is_file(p)
+ }
+
fn drain(&self) -> Result<Drain, SE> {
self.backend_cloned().map(Drain::new)
}
diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs
index c376ecc..0e0c57d 100644
--- a/lib/core/libimagstore/src/store.rs
+++ b/lib/core/libimagstore/src/store.rs
@@ -812,17 +812,21 @@ impl Store {
self.backend
.pathes_recursively(self.path().clone())
.and_then(|iter| {
- let iter : Result<Vec<StoreId>> = iter
- .map(|path| StoreId::from_full_path(self.path(), path))
- .fold(Ok(vec![]), |acc, elem| {
- acc.and_then(move |mut a| {
- a.push(try!(elem));
- Ok(a)
- })
- });
-
- let iter = try!(iter);
- Ok(StoreIdIterator::new(Box::new(iter.into_iter())))
+ let mut elems = vec![];
+ for element in iter {
+ let is_file = {
+ let mut base = self.path().clone();
+ base.push(element.clone());
+ println!("Checking: {:?}", base);
+ try!(self.backend.is_file(&base))
+ };
+
+ if is_file {
+ let sid = try!(StoreId::from_full_path(self.path(), element));
+ elems.push(sid);
+ }
+ }
+ Ok(StoreIdIterator::new(Box::new(elems.into_iter())))
})
}