From 25f5655e1b2a63a2b095758013c841f4738fd48b Mon Sep 17 00:00:00 2001 From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr> Date: Tue, 10 May 2022 16:29:18 +0200 Subject: [PATCH] src/commit.rs: add check_path function --- src/commit.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/commit.rs b/src/commit.rs index 9e2f08d..2ca56a4 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -1,5 +1,17 @@ use crate::init; -use std::process::{exit, Command}; +use std::{process::{exit, Command}, path::PathBuf}; + + +/// Check if .borg repository and results folder exists +pub fn check_path() -> (PathBuf, PathBuf) { + let (borg_folder, results_folder) = init::get_borg_folder(); + if !borg_folder.is_dir() { + eprintln!("{} folder not found !", borg_folder.to_str().unwrap()); + exit(2) + } + (borg_folder, results_folder) +} + /// Get the current commit name of a git repository /// @@ -26,7 +38,7 @@ pub fn get_current_commit() -> String { /// Create a commit of the results folder named as the current git commit id pub fn commit(compression: String) { - let (borg_folder, results_folder) = init::get_borg_folder(); + let (borg_folder, results_folder) = check_path(); let commit = get_current_commit(); let output = Command::new("borg") .arg("create") -- GitLab