feat: add directory recursion
Diff
Cargo.lock | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
Cargo.toml | 1 +
src/cli.rs | 12 ++++++------
src/main.rs | 12 ++++++++++--
4 files changed, 68 insertions(+), 8 deletions(-)
@@ -173,6 +173,7 @@ dependencies = [
"humantime",
"serde",
"tokio",
"walkdir",
]
[[package]]
@@ -317,6 +318,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[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.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -427,12 +437,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "walkdir"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -10,3 +10,4 @@ clap = { version = "4.4.18", features = ["derive"] }
humantime = "2.1.0"
serde = { version = "1.0.195", features = ["derive"] }
tokio = { version = "1.35.1", features = ["full"] }
walkdir = "2.4.0"
@@ -5,12 +5,6 @@ use humantime::Duration;
use crate::error::ParseError;
#[derive(Debug, Parser)]
pub struct CliArgs {
@@ -24,6 +18,11 @@ pub struct CliArgs {
#[clap(required = true)]
#[arg(value_parser = parse_directory)]
pub directory: PathBuf,
#[clap(short, long, default_value_t = 3)]
pub max_recursion_depth: usize,
}
impl Default for CliArgs {
@@ -31,6 +30,7 @@ impl Default for CliArgs {
Self {
refresh_time: parse_refresh_time("10m").unwrap(),
directory: Default::default(),
max_recursion_depth: 3,
}
}
}
@@ -1,6 +1,7 @@
use clap::Parser;
use cli::CliArgs;
use tokio::time::sleep;
use walkdir::WalkDir;
mod cli;
mod error;
@@ -13,8 +14,15 @@ async fn main() {
}
async fn do_sync_task(args: CliArgs) {
println!("I am awake! {:?}", args);
for dir in WalkDir::new(args.directory)
.max_depth(3)
.into_iter()
.filter_map(|err| err.ok())
{
println!("TODO: sync {:?}", dir);
}
println!("Sleeping until the next refresh.");
sleep(args.refresh_time.into()).await;
}