use walkdir create in another place instead of custom code
This commit is contained in:
parent
dedee2ef08
commit
a38385f3b5
1 changed files with 7 additions and 22 deletions
|
|
@ -20,28 +20,13 @@ pub struct CreateTorrentOptions<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn walk_dir_find_paths(dir: &Path, out: &mut Vec<Cow<'_, Path>>) -> anyhow::Result<()> {
|
fn walk_dir_find_paths(dir: &Path, out: &mut Vec<Cow<'_, Path>>) -> anyhow::Result<()> {
|
||||||
let mut stack = vec![Cow::Borrowed(dir)];
|
out.extend(
|
||||||
while let Some(dir) = stack.pop() {
|
walkdir::WalkDir::new(dir)
|
||||||
let rd = std::fs::read_dir(&dir).with_context(|| format!("error reading {:?}", dir))?;
|
.into_iter()
|
||||||
for element in rd {
|
.filter_map(|e| e.ok())
|
||||||
let element =
|
.filter(|e| e.file_type().is_file())
|
||||||
element.with_context(|| format!("error reading DirEntry from {:?}", dir))?;
|
.map(|e| e.path().to_owned().into()),
|
||||||
let ft = element.file_type().with_context(|| {
|
);
|
||||||
format!(
|
|
||||||
"error determining filetype of DirEntry {:?} while reading {:?}",
|
|
||||||
element.file_name(),
|
|
||||||
dir
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let full_path = Cow::Owned(dir.join(element.file_name()));
|
|
||||||
if ft.is_dir() {
|
|
||||||
stack.push(full_path);
|
|
||||||
} else {
|
|
||||||
out.push(full_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue