From 059914a2938699d6bd8319d92b02fe811cda2b97 Mon Sep 17 00:00:00 2001 From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr> Date: Wed, 11 May 2022 11:07:33 +0200 Subject: [PATCH] src/commit.rs: add delete_commit function --- src/commit.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/commit.rs b/src/commit.rs index 7e3c665..3af86bb 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -37,12 +37,33 @@ 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") + .arg("delete") + .arg(format!("{}::{}", borg_path.to_str().unwrap(), commit)) + .output() + .unwrap(); + match output.status.code().unwrap() { + 0 => (), + num => { + eprintln!("{}", String::from_utf8(output.stderr).unwrap()); + exit(num); + } + } +} + + /// Create a commit of the results folder named as the current git commit id -pub fn commit(compression: String, mut commit: String) { +pub fn commit(compression: String, mut commit: String, update: bool) { let (borg_folder, results_folder) = check_path(); if commit == String::from("") { commit = get_current_commit(); } + if update { + delete_commit(&commit, &borg_folder); + } let output = Command::new("borg") .arg("create") .arg("--stats") -- GitLab