summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-08-24 13:05:13 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-08-26 12:30:25 +0200
commit4defd24f134cc657dafec4b3925097fe977a36cd (patch)
treee0853367b506a93bd8374f4651f7dd511cf1f9b6
parente50de5ff1fae148c345f95cf0ec2d712533ef406 (diff)
Fix: do not filter out directories
Because the filter_entry() method is expected for the recursion to happen, we should not filter out directories here (except hidden ones). Rather filter them out later in the process. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/repository/fs.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/repository/fs.rs b/src/repository/fs.rs
index 9fc4008..4cf1829 100644
--- a/src/repository/fs.rs
+++ b/src/repository/fs.rs
@@ -12,6 +12,7 @@ use anyhow::anyhow;
use anyhow::Context;
use anyhow::Result;
use anyhow::Error;
+use resiter::Filter;
use resiter::Map;
use resiter::AndThen;
@@ -90,12 +91,14 @@ impl FileSystemRepresentation {
files: vec![],
};
+ log::trace!("Loading files from filesystem starting at: {}", root.display());
WalkDir::new(root)
.follow_links(false)
.max_open(100)
.same_file_system(true)
.into_iter()
- .filter_entry(|e| is_pkgtoml(e))
+ .filter_entry(|e| !is_hidden(e) && (is_pkgtoml(e) || is_dir(e)))
+ .filter_ok(|e| is_pkgtoml(e))
.inspect(|el| log::trace!("Loading: {:?}", el))
.map_err(Error::from)
.and_then_ok(|de| {
@@ -193,11 +196,23 @@ impl FileSystemRepresentation {
}
}
+fn is_hidden(entry: &DirEntry) -> bool {
+ log::trace!("Check {:?} is hidden", entry);
+ entry.file_name().to_str().map(|s| s.starts_with(".")).unwrap_or(false)
+}
+
+fn is_dir(entry: &DirEntry) -> bool {
+ log::trace!("Check {:?} is directory", entry);
+ entry.file_type().is_dir()
+}
+
fn is_pkgtoml(entry: &DirEntry) -> bool {
+ log::trace!("Check {:?} == 'pkg.toml'", entry);
entry.file_name().to_str().map(|s| s == "pkg.toml").unwrap_or(false)
}
fn load_file(path: &Path) -> Result<String> {
+ log::trace!("Reading {}", path.display());
std::fs::read_to_string(path)
.with_context(|| anyhow!("Reading file from filesystem: {}", path.display()))
.map_err(Error::from)