forked from Cutieguwu/raven
Most of the refactor. Need to switch machines.
This commit is contained in:
14
crates/fs/Cargo.toml
Normal file
14
crates/fs/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "fs"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
description = "Raven's FS utilities"
|
||||
repository.workspace = true
|
||||
|
||||
publish.workspace = true
|
||||
test.workspace = true
|
||||
|
||||
[dependencies]
|
||||
derive_more.workspace = true
|
||||
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