Skip to content

Commit

Permalink
Check that source exists before returning it
Browse files Browse the repository at this point in the history
It's possible for a config to name a source that doesn't actually exist
in the repo.
  • Loading branch information
cmyr committed Sep 19, 2024
1 parent 6f41fdf commit 6eee303
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/repo_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<PathBuf>, 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<Vec<PathBuf>, LoadRepoError> {
let font_dir = git_cache_dir.join(self.repo_name());

if !font_dir.exists() {
std::fs::create_dir_all(&font_dir)?;
Expand Down Expand Up @@ -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::<Vec<_>>();
sources.sort_unstable();
sources.dedup();
Expand Down

0 comments on commit 6eee303

Please sign in to comment.