feat: use local copy when NAS_HOST is localhost

Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
Chaos Rogers 2025-08-17 14:03:12 +01:00
parent 26824c458d
commit 8d58e50847
2 changed files with 20 additions and 11 deletions

View file

@ -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"

View file

@ -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.");