Skip to content
Snippets Groups Projects
Commit 0ffe76d7 authored by nfontrod's avatar nfontrod
Browse files

src/commit.rs: update to display borg commit progression

parent 90d51bf3
No related branches found
No related tags found
No related merge requests found
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);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment