diff --git a/src/commit.rs b/src/commit.rs index 7e3c6651f5a5544420b05655b27305f1ea3c6b36..3af86bb103f939aaebedc0b257adecce26f4a869 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")