forked from Cutieguwu/raven
Most of the refactor. Need to switch machines.
This commit is contained in:
24
crates/fs/src/lib.rs
Normal file
24
crates/fs/src/lib.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub const EXT_TOML: &str = ".toml";
|
||||
pub const EXT_LOCK: &str = ".lock";
|
||||
|
||||
pub fn expand_files<P: AsRef<Path>>(path: P) -> std::io::Result<Vec<PathBuf>> {
|
||||
let path = path.as_ref();
|
||||
|
||||
if path.is_file() {
|
||||
return Ok(vec![path.to_path_buf()]);
|
||||
}
|
||||
|
||||
Ok(std::fs::read_dir(path)?
|
||||
.filter_map(|entry| {
|
||||
let path = entry.ok()?.path();
|
||||
if path.is_dir() {
|
||||
Some(expand_files(path).ok()?)
|
||||
} else {
|
||||
Some(vec![path])
|
||||
}
|
||||
})
|
||||
.flatten()
|
||||
.collect())
|
||||
}
|
||||
Reference in New Issue
Block a user