diff --git a/src/clean.rs b/src/clean.rs new file mode 100644 index 0000000000000000000000000000000000000000..34aa93af79ee779944ba9d78fde516ba46a31922 --- /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); + } + }; +}