diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-12-30 09:53:42 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-12-30 09:53:42 +0200 |
commit | 6a320c72901c7e1d4b69e4613a4af7ceb1b0da36 (patch) | |
tree | cdd089dc8b4e477bb1df0ffa31f120f1a0fa7168 /src/bin | |
parent | a6a9494e986fe6b70350ff098d624ac33f0fa849 (diff) | |
download | summain-rs-6a320c72901c7e1d4b69e4613a4af7ceb1b0da36.tar.gz |
feat: traverse directories
Sponsored-by: author
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/summain.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/bin/summain.rs b/src/bin/summain.rs index 58d8788..9365243 100644 --- a/src/bin/summain.rs +++ b/src/bin/summain.rs @@ -1,12 +1,17 @@ use anyhow::Context; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use structopt::StructOpt; use summain::ManifestEntry; +use walkdir::WalkDir; #[tokio::main] async fn main() -> anyhow::Result<()> { - let mut opt = Opt::from_args(); - opt.pathnames[..].sort(); + let opt = Opt::from_args(); + let mut files = vec![]; + for pathname in opt.pathnames { + find(&pathname, &mut files)?; + } + files.sort(); // Get metadata about all files, but don't compute checksum yet. // @@ -18,7 +23,7 @@ async fn main() -> anyhow::Result<()> { // large: Linux only allows 128 KiB of command line arguments. let mut handles = vec![]; - for filename in opt.pathnames.iter().cloned() { + for filename in files.iter().cloned() { handles.push(tokio::spawn(async move { manifest(filename).await })); } @@ -49,6 +54,13 @@ async fn main() -> anyhow::Result<()> { Ok(()) } +fn find(root: &Path, files: &mut Vec<PathBuf>) -> anyhow::Result<()> { + for e in WalkDir::new(root) { + files.push(e?.path().to_path_buf()); + } + Ok(()) +} + #[derive(StructOpt, Debug)] struct Opt { #[structopt(parse(from_os_str))] |