From fa4e89c88547cea2567cafa1496270e77eacba56 Mon Sep 17 00:00:00 2001 From: Spencer Kohan Date: Sun, 19 Apr 2020 12:53:43 +0200 Subject: [PATCH] improved rsync output handling: --- src/main.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index f28858d..701c18b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,28 +12,32 @@ use crate::config::SessionConfig; use crate::cli::SubCommand; use crate::cli::CliOptions; use structopt::StructOpt; -use std::io::prelude::*; use std::path::Path; // Perform rsync from source to destination fn sync(config: &config::SessionConfig) { use std::process::Command; + use std::process::Stdio; fn rsync(source: &str, destinatin: &str, args: &Vec) { - let output = &Command::new("rsync") + println!("executing rsync: {} {}", source, destinatin); + + let mut rsync = Command::new("rsync") .arg("-v") // verbose output .arg("-a") // archived: we use this to only sync files which have changed .arg("-r") // recursive .args(args) .arg(source) .arg(destinatin) - .output() + .stdout(Stdio::inherit()) + .spawn() .expect("failed to execute rsync"); - std::io::stdout().write_all(&output.stdout).unwrap(); - std::io::stderr().write_all(&output.stderr).unwrap(); - assert!(output.status.success()); + let result = rsync.wait().expect("failed to wait for process"); + + println!("rsync finished"); + assert!(result.success()); } // we sync actions explicitly here, since they might be ignored otherwise