From 8d58e508472ac66538476695a4763dd0693b2ab8 Mon Sep 17 00:00:00 2001 From: John Rogers Date: Sun, 17 Aug 2025 14:03:12 +0100 Subject: [PATCH] feat: use local copy when NAS_HOST is localhost Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) --- Cargo.toml | 1 + src/main.rs | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index be5b04c..ad29e98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ edition = "2021" [dependencies] anyhow = "1.0.82" clap = { version = "4.5.4", features = ["derive"] } +fs_extra = "1.3.0" tempfile = "3.10.1" diff --git a/src/main.rs b/src/main.rs index e4f408b..c636a54 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,18 +79,26 @@ fn transfer_files(source_path: &Path) -> Result<()> { let is_empty = fs::read_dir(source_path)?.next().is_none(); if !is_empty { - println!("[INFO] Transferring files to NAS..."); - let mut scp_cmd = Command::new("scp"); - let source = format!( - "{}/.", - source_path.to_str().context("Invalid source path")? - ); - let destination = format!("{}@{}:{}", NAS_USER, NAS_HOST, NAS_PATH); - scp_cmd.args(["-r", &source, &destination]); + if NAS_HOST == "localhost" { + println!("[INFO] NAS_HOST is localhost, copying files locally..."); + let mut options = fs_extra::dir::CopyOptions::new(); + options.content_only = true; + fs_extra::dir::copy(source_path, NAS_PATH, &options) + .context("Failed to copy files locally")?; + } else { + println!("[INFO] Transferring files to NAS via scp..."); + let mut scp_cmd = Command::new("scp"); + let source = format!( + "{}/.", + source_path.to_str().context("Invalid source path")? + ); + let destination = format!("{}@{}:{}", NAS_USER, NAS_HOST, NAS_PATH); + scp_cmd.args(["-r", &source, &destination]); - let status = scp_cmd.status().context("Failed to execute scp")?; - if !status.success() { - anyhow::bail!("scp failed with status: {}", status); + let status = scp_cmd.status().context("Failed to execute scp")?; + if !status.success() { + anyhow::bail!("scp failed with status: {}", status); + } } } else { println!("[WARN] No files found to transfer.");