From e40a49822f88695d2b9ef553855704d15b0d96d9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 23 Aug 2021 09:54:49 +0200 Subject: Add method to get all pkg.toml file contents for a path Signed-off-by: Matthias Beyer --- src/repository/fs.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/repository') diff --git a/src/repository/fs.rs b/src/repository/fs.rs index a865f3f..c648126 100644 --- a/src/repository/fs.rs +++ b/src/repository/fs.rs @@ -106,6 +106,25 @@ impl FileSystemRepresentation { Ok(fsr) } + + pub fn get_files_for<'a>(&'a self, path: &Path) -> Result> { + let mut res = Vec::with_capacity(10); // good enough + + let mut curr_hm = &self.elements; + for elem in path.components() { + let elem = PathComponent::try_from(&elem)?; + + match curr_hm.get(&elem) { + Some(Element::File(cont)) => res.push(cont), + Some(Element::Dir(hm)) => curr_hm = hm, + None => { + unimplemented!() + }, + } + } + + Ok(res) + } } fn is_pkgtoml(entry: &DirEntry) -> bool { -- cgit v1.2.3