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 | |
parent | a6a9494e986fe6b70350ff098d624ac33f0fa849 (diff) | |
download | summain-rs-6a320c72901c7e1d4b69e4613a4af7ceb1b0da36.tar.gz |
feat: traverse directories
Sponsored-by: author
-rw-r--r-- | Cargo.lock | 32 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/bin/summain.rs | 20 |
3 files changed, 49 insertions, 4 deletions
@@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "ansi_term" version = "0.11.0" @@ -310,6 +312,15 @@ dependencies = [ ] [[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -418,6 +429,7 @@ dependencies = [ "structopt", "tokio", "unix_mode", + "walkdir", ] [[package]] @@ -514,6 +526,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -530,6 +553,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -20,3 +20,4 @@ sha2 = "0.9" structopt = "0.3" tokio = { version = "1", features = ["full"] } unix_mode = "0.1" +walkdir = "2.3.2" 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))] |