From 6eee303f97194351150edb8a81c3da262356b721 Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Thu, 19 Sep 2024 12:46:37 -0400 Subject: [PATCH] Check that source exists before returning it It's possible for a config to name a source that doesn't actually exist in the repo. --- src/repo_info.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/repo_info.rs b/src/repo_info.rs index 5bbdece..5d5832a 100644 --- a/src/repo_info.rs +++ b/src/repo_info.rs @@ -58,9 +58,9 @@ impl RepoInfo { /// Return the a `Vec` of source files in this respository. /// /// If necessary, this will create a new checkout of this repo at - /// '{font_dir}/{repo_name}'. - pub fn get_sources(&self, font_repos_dir: &Path) -> Result, LoadRepoError> { - let font_dir = font_repos_dir.join(self.repo_name()); + /// '{git_cache_dir}/{repo_name}'. + pub fn get_sources(&self, git_cache_dir: &Path) -> Result, LoadRepoError> { + let font_dir = git_cache_dir.join(self.repo_name()); if !font_dir.exists() { std::fs::create_dir_all(&font_dir)?; @@ -89,7 +89,10 @@ impl RepoInfo { let mut sources = configs .iter() .flat_map(|c| c.sources.iter()) - .map(|source| source_dir.join(source)) + .filter_map(|source| { + let source = source_dir.join(source); + source.exists().then_some(source) + }) .collect::>(); sources.sort_unstable(); sources.dedup();