use std::path::{Path, PathBuf};
use ignore::WalkBuilder;
use super::relative_path;
pub struct WalkResult {
pub files: Vec<(PathBuf, u64)>,
pub dirs: Vec<PathBuf>,
}
pub fn walk(root: &Path) -> WalkResult {
let mut files = Vec::new();
let mut dirs = Vec::new();
for result in WalkBuilder::new(root).build() {
let Ok(entry) = result else {
continue; };
let rel = relative_path(entry.path(), root);
if rel.as_os_str().is_empty() {
continue; }
match entry.file_type() {
Some(ft) if ft.is_dir() => dirs.push(rel),
Some(ft) if ft.is_file() => {
let bytes = entry.metadata().map(|m| m.len()).unwrap_or(0);
files.push((rel, bytes));
}
_ => {}
}
}
WalkResult { files, dirs }
}