1// Forked from atrium-codegen
2// https://github.com/sugyan/atrium/blob/main/lexicon/atrium-codegen/src/fs.rs
3
4use std::ffi::OsStr;
5use std::fs::read_dir;
6use std::io::Result;
7use std::path::{Path, PathBuf};
8
9fn walk<F>(path: &Path, results: &mut Vec<PathBuf>, f: &mut F) -> Result<()>
10where
11 F: FnMut(&Path) -> bool,
12{
13 if f(path) {
14 results.push(path.into());
15 }
16 if path.is_dir() {
17 for entry in read_dir(path)? {
18 walk(&entry?.path(), results, f)?;
19 }
20 }
21 Ok(())
22}
23
24pub(crate) fn find_schemas(path: &Path) -> Result<Vec<impl AsRef<Path>>> {
25 let mut results = Vec::new();
26 walk(path, &mut results, &mut |path| {
27 path.extension().and_then(OsStr::to_str) == Some("json")
28 })?;
29 Ok(results)
30}