Skip to content

Commit

Permalink
use walkdir create in another place instead of custom code
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatson committed Sep 13, 2024
1 parent dedee2e commit a38385f
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions crates/librqbit/src/create_torrent_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,13 @@ pub struct CreateTorrentOptions<'a> {
}

fn walk_dir_find_paths(dir: &Path, out: &mut Vec<Cow<'_, Path>>) -> anyhow::Result<()> {
let mut stack = vec![Cow::Borrowed(dir)];
while let Some(dir) = stack.pop() {
let rd = std::fs::read_dir(&dir).with_context(|| format!("error reading {:?}", dir))?;
for element in rd {
let element =
element.with_context(|| format!("error reading DirEntry from {:?}", dir))?;
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);
}
}
}
out.extend(
walkdir::WalkDir::new(dir)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| e.file_type().is_file())
.map(|e| e.path().to_owned().into()),
);
Ok(())
}

Expand Down

0 comments on commit a38385f

Please sign in to comment.