summaryrefslogtreecommitdiffstats
path: root/src/repository
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-08-23 10:05:36 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-08-26 12:30:21 +0200
commit60ea0e6675e3fca4ff1b48245a1609999a00faed (patch)
tree2012524ac88898cc70451e134d74c161e8bc6bd4 /src/repository
parente40a49822f88695d2b9ef553855704d15b0d96d9 (diff)
Add helper fn to check whether a file is a leaf
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/repository')
-rw-r--r--src/repository/fs.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/repository/fs.rs b/src/repository/fs.rs
index c648126..3b7972f 100644
--- a/src/repository/fs.rs
+++ b/src/repository/fs.rs
@@ -107,6 +107,41 @@ impl FileSystemRepresentation {
Ok(fsr)
}
+ pub fn is_leaf_file(&self, path: &Path) -> Result<bool> {
+ let mut curr_hm = &self.elements;
+
+ fn toml_files_in_tree(hm: &HashMap<PathComponent, Element>) -> bool {
+ for value in hm.values() {
+ match value {
+ Element::File(_) => return true,
+ Element::Dir(hm) => if toml_files_in_tree(hm) {
+ return true
+ },
+ }
+ }
+ false
+ }
+
+ for elem in path.components() {
+ let elem = PathComponent::try_from(&elem)?;
+
+ match curr_hm.get(&elem) {
+ Some(Element::File(_)) => {
+ // if I have a file now, and the current hashmap only holds either
+ // * No directory
+ // * or a directory where all subdirs do not contain a pkg.toml
+ return Ok(curr_hm.values().count() == 1 || !toml_files_in_tree(curr_hm))
+ },
+ Some(Element::Dir(hm)) => curr_hm = hm,
+ None => {
+ unimplemented!()
+ },
+ }
+ }
+
+ Ok(false)
+ }
+
pub fn get_files_for<'a>(&'a self, path: &Path) -> Result<Vec<&'a String>> {
let mut res = Vec::with_capacity(10); // good enough