From 0ffe76d7887903de6005d9744681151b52fa122a Mon Sep 17 00:00:00 2001 From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr> Date: Thu, 12 May 2022 11:08:43 +0200 Subject: [PATCH] src/commit.rs: update to display borg commit progression --- src/commit.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/commit.rs b/src/commit.rs index 6682fb6..f6afdbb 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -1,7 +1,7 @@ use crate::init; use std::{ path::PathBuf, - process::{exit, Command}, + process::{exit, Command, Stdio}, }; /// Check if .borg repository and results folder exists @@ -37,7 +37,6 @@ pub fn get_current_commit() -> String { commit } - /// function that deletes commit if needed pub fn delete_commit(commit: &str, borg_path: &PathBuf) { let output = Command::new("borg") @@ -54,7 +53,6 @@ pub fn delete_commit(commit: &str, borg_path: &PathBuf) { } } - /// Create a commit of the results folder named as the current git commit id pub fn commit(compression: String, mut commit_id: String, update: bool) { let (borg_folder, results_folder) = check_path(); @@ -64,7 +62,7 @@ pub fn commit(compression: String, mut commit_id: String, update: bool) { if update { delete_commit(&commit_id, &borg_folder); } - let output = Command::new("borg") + let mut output = Command::new("borg") .arg("create") .arg("--stats") .arg("--progress") @@ -72,12 +70,17 @@ pub fn commit(compression: String, mut commit_id: String, update: bool) { .arg(compression) .arg(format!("{}::{}", borg_folder.to_str().unwrap(), commit_id)) .arg(results_folder.to_str().unwrap()) - .output() - .unwrap(); - match output.status.code().unwrap() { + .stdout(Stdio::piped()) + .spawn() + .unwrap_or_else(|e| { + eprintln!("An error occured during borg create ! {}", e); + exit(8); + }); + let ecode = output.wait().expect("error"); + match ecode.code().unwrap() { 0 => (), num => { - eprintln!("{}", String::from_utf8(output.stderr).unwrap()); + eprintln!("{}", ecode.to_string()); exit(num); } } -- GitLab