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 crate::init;
use std::{ use std::{
path::PathBuf, path::PathBuf,
process::{exit, Command}, process::{exit, Command, Stdio},
}; };
/// Check if .borg repository and results folder exists /// Check if .borg repository and results folder exists
...@@ -37,7 +37,6 @@ pub fn get_current_commit() -> String { ...@@ -37,7 +37,6 @@ pub fn get_current_commit() -> String {
commit commit
} }
/// function that deletes commit if needed /// function that deletes commit if needed
pub fn delete_commit(commit: &str, borg_path: &PathBuf) { pub fn delete_commit(commit: &str, borg_path: &PathBuf) {
let output = Command::new("borg") let output = Command::new("borg")
...@@ -54,7 +53,6 @@ pub fn delete_commit(commit: &str, borg_path: &PathBuf) { ...@@ -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 /// 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) { pub fn commit(compression: String, mut commit_id: String, update: bool) {
let (borg_folder, results_folder) = check_path(); let (borg_folder, results_folder) = check_path();
...@@ -64,7 +62,7 @@ pub fn commit(compression: String, mut commit_id: String, update: bool) { ...@@ -64,7 +62,7 @@ pub fn commit(compression: String, mut commit_id: String, update: bool) {
if update { if update {
delete_commit(&commit_id, &borg_folder); delete_commit(&commit_id, &borg_folder);
} }
let output = Command::new("borg") let mut output = Command::new("borg")
.arg("create") .arg("create")
.arg("--stats") .arg("--stats")
.arg("--progress") .arg("--progress")
...@@ -72,12 +70,17 @@ pub fn commit(compression: String, mut commit_id: String, update: bool) { ...@@ -72,12 +70,17 @@ pub fn commit(compression: String, mut commit_id: String, update: bool) {
.arg(compression) .arg(compression)
.arg(format!("{}::{}", borg_folder.to_str().unwrap(), commit_id)) .arg(format!("{}::{}", borg_folder.to_str().unwrap(), commit_id))
.arg(results_folder.to_str().unwrap()) .arg(results_folder.to_str().unwrap())
.output() .stdout(Stdio::piped())
.unwrap(); .spawn()
match output.status.code().unwrap() { .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 => (), 0 => (),
num => { num => {
eprintln!("{}", String::from_utf8(output.stderr).unwrap()); eprintln!("{}", ecode.to_string());
exit(num); exit(num);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment