From 8166c524077391d98010fb4fb5d32e7a3aa18a55 Mon Sep 17 00:00:00 2001 From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr> Date: Tue, 31 Jan 2023 14:19:47 +0100 Subject: [PATCH] src/clean.rs: add clean module --- src/clean.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/clean.rs diff --git a/src/clean.rs b/src/clean.rs new file mode 100644 index 0000000..34aa93a --- /dev/null +++ b/src/clean.rs @@ -0,0 +1,31 @@ +use crate::commit; +use colored::Colorize; +use std::{path::PathBuf, process::exit}; + +/// Get the path of the .tmp folder +/// +/// # Description +/// Get the path of the .tmp folder at the root of the project folder but don't +/// create it +pub(crate) fn get_tmp_path(borgfolder: &PathBuf) -> PathBuf { + let mut tmp_folder = borgfolder.parent().unwrap().to_path_buf(); + tmp_folder.push(".tmp"); + tmp_folder +} + +/// Function used to remove the .tmp repository +pub fn clean() { + let (borg_folder, _) = commit::check_path(); + let tmp_folder = get_tmp_path(&borg_folder); + if !tmp_folder.is_dir() { + println!("{}: The .tmp folder doesn't exits !", "info".blue()); + return (); + } + match std::fs::remove_dir_all(&tmp_folder) { + Ok(_) => (), + Err(e) => { + eprintln!("{}: Unable to remove .tmp directory. {}", "error".red(), e); + exit(1); + } + }; +} -- GitLab