diff --git a/src/clone.rs b/src/clone.rs index f653412a2f6a2289d94c8f40c3b92f5b57666e90..fe5f4bc053f7b144bc8d25338a2b5eff70fb1575 100644 --- a/src/clone.rs +++ b/src/clone.rs @@ -1,119 +1,3 @@ // SPDX-FileCopyrightText: 2023 Nicolas Fontrodona // // SPDX-License-Identifier: AGPL-3.0-or-later - -use std::path::PathBuf; -use std::process::exit; -use std::process::Command; - -use colored::Colorize; - -use crate::configt; -use crate::create_hooks; -use crate::init; -use crate::push; -use crate::remote; - -fn check_remote_dir(url: &PathBuf, adress: &str) { - if !push::check_dir_exist(url, adress) { - eprintln!("{}: {} no such directory", "error".red(), url.display()); - exit(1); - } - let v = vec!["data", "config", "archive_list"]; - for file in v { - let mut path = url.clone(); - path.push(file); - let exists = match file { - "data" => push::check_dir_exist(&path, adress), - _ => push::check_file_exist(&path, adress), - }; - if !exists { - let kind = if file == "data" { "folder" } else { "file" }; - eprintln!( - "{}: no {} {} inside {} directory", - "error".red(), - file, - kind, - url.display() - ); - exit(1); - } - } -} - -/// Function used to get borg repository folder only if -/// the project is inside a git repository and a results folder exits -/// # Return -/// Absolute path to borg repository -pub fn get_borg_absolute_folder() -> PathBuf { - let output = Command::new("git") - .arg("rev-parse") - .arg("--show-cdup") - .output() - .unwrap(); - match output.status.code().unwrap() { - 128 => { - eprintln!("Not a git repository !"); - exit(128); - } - 127 => { - eprintln!("Git not found !"); - exit(127); - } - 0 => (), - num => { - eprintln!("{}", String::from_utf8(output.stderr).unwrap()); - exit(num) - } - } - let mut string_path = String::from_utf8(output.stdout).unwrap(); - if string_path.ends_with('\n') { - string_path.pop(); - } - if string_path.is_empty() { - string_path.push_str("./"); - } - let mut p = PathBuf::from(&string_path).canonicalize().unwrap(); - let mut results = p.clone(); - p.push(".borg"); - results.push("results"); - if !results.is_dir() { - eprintln!("{} not found !", results.to_str().unwrap()); - exit(1); - } - p -} - -/// Create a push the tar achive on the selected remote path -/// # Arguments -/// - `remote`: The name of a remote -/// - `hooks`: a bolean indicating whether or not to use hooks -/// - `compression`: The compression that will be used when creating an archive -/// - `mode`: The mode used for checkout -pub fn clone(path: &str, hooks: bool, compression: &str, mode: &str) -> () { - let (adress, url) = push::split_path(path); - let borg_folder = get_borg_absolute_folder(); - if borg_folder.is_dir() { - eprintln!( - "{}: {} already exits.", - "error".red(), - &borg_folder.display() - ); - exit(1); - } - check_remote_dir(&url, &adress); - push::copy_file(&borg_folder, &url, &adress, "clone"); - let name = url.file_name().unwrap().to_str().unwrap(); - configt::create_named_local_config(name); - let pf = url.parent().unwrap().to_path_buf(); - let full_url = if adress != "file" { - format!("{}:{}", &adress, &pf.display()) - } else { - pf.to_str().unwrap().to_owned() - }; - remote::update_config("origin", &full_url, false); - init::update_gitignores(); - if hooks { - create_hooks::create_hooks(compression, mode); - } -} diff --git a/src/config_structure.rs b/src/config_structure.rs index 625eb7ef2bc82199c3afc20e959b4ffcfbb1e101..a609cba5834de7d9c2ce1b311f45a46d46f7d505 100644 --- a/src/config_structure.rs +++ b/src/config_structure.rs @@ -26,16 +26,6 @@ impl Config { gblk_remote: None, } } - pub fn new_named(name: &str) -> Config { - Config { - gblk_project_name: GblkName::new_named(name), - gblk_prune: None, - gblk_remote: None, - } - } - pub fn get_name(&self) -> Option<String> { - self.gblk_project_name.name.clone() - } pub fn check_project_type(&self, is_global: bool, path: &PathBuf) -> () { if is_global { if &self.gblk_project_name.config_type != "global" { @@ -163,10 +153,4 @@ impl GblkName { } } } - pub fn new_named(name: &str) -> GblkName { - GblkName { - name: Some(String::from(name)), - config_type: String::from("local"), - } - } } diff --git a/src/configt.rs b/src/configt.rs index 252fc766d169b6960669dfb1191763640ee8b70b..58d49509bc07020e8fc19afb24cacaba240aba96 100644 --- a/src/configt.rs +++ b/src/configt.rs @@ -362,13 +362,6 @@ pub fn create_local_config() { write_config(&conf, false); } -/// Create a named local config file -/// # Arguments -/// - `name`: The name of the config file -pub fn create_named_local_config(name: &str) { - let conf = Config::new_named(name); - write_config(&conf, false); -} /// Function that update the current gblk config file for the project folder /// # Arguments @@ -428,17 +421,6 @@ pub fn remove_config(key: &str, global: bool) -> () { }; } -/// Get the name of the current project -pub(crate) fn get_project_name() -> String { - let config = parse_toml(false); - match config.get_name() { - None => { - eprintln!("{}: Unable to get the project name !", "error".red()); - exit(1); - } - Some(name) => name, - } -} /// Function that recover the local or global gblk config /// # Description diff --git a/src/init.rs b/src/init.rs index e26bbf4150995bde16ca6fb0c6e165d92ee430e9..564cc7202599f0e634dc91441abdc716bd67b61f 100644 --- a/src/init.rs +++ b/src/init.rs @@ -121,6 +121,7 @@ pub(crate) fn update_gitignores() { update_gitignore(&giti_res, "*\n!.gitignore"); } + /// Creation of a borg repository and creation of hooks if needed inside `.git/hooks` /// folder /// # Arguments: diff --git a/src/list.rs b/src/list.rs index d52cd532f16fcceac5d91920a8801e695fb9cab6..7babe49c57a6bece6cea5b25f7e82de832a4ff6c 100644 --- a/src/list.rs +++ b/src/list.rs @@ -4,33 +4,8 @@ use crate::commit; use colored::Colorize; -use std::process::{exit, Command, Output, Stdio}; +use std::process::{exit, Command, Stdio}; -/// Launch borglist command and return the ouput object of results -/// Arguments: -/// * `first`: Consider first N archives -/// * `last`: Consider last N archive -/// * `archive`: An archive name for which we want to know file content -pub fn borg_list_launcher(first: i32, last: i32, archive: &str) -> Output { - let mut args = String::from(""); - if first != 0 { - args.push_str(&format!("--first {} ", first)); - } - if last != 0 { - args.push_str(&format!("--last {} ", last)); - } - let (borg_path, _) = commit::check_path(); - let mut bp: String = String::from(""); - if archive != "" { - bp.push_str(&format!("{}::{}", borg_path.to_str().unwrap(), archive)); - } else { - bp.push_str(borg_path.to_str().unwrap()); - } - args.push_str(&bp); - let cmd = format!("borg list {}", args); - let output = Command::new("sh").arg("-c").arg(cmd).output().unwrap(); - output -} /// List the content of the borg archive /// Arguments: diff --git a/src/main.rs b/src/main.rs index 918631ed2d3f0f3a41c62e03d330a386919edf61..8181e06ce7d9d5ce456d04b095d172f57c2977ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -328,6 +328,11 @@ struct RemoteRm { struct Push { /// The name of the remote to use key: String, + /// The name of the archive to push + archive: String, + /// The compression to use when pushin a commit + #[clap(short, long, default_value = "lz4", value_name = "COMPRESSION")] + compression: String, } #[derive(Debug, Args)] @@ -438,19 +443,23 @@ fn main() { Remote::Rm(e) => remote::remove_config(&e.key, e.global), }, Commands::Push(p) => { - push::push(&p.key); + mount::umount_archive(true); + push::push(&p.key, &p.archive, &p.compression); } - Commands::Pull(p) => { - pull::pull(&p.key); + Commands::Pull(_) => { + // pull::pull(&p.key); + eprintln!("function disabled"); } Commands::Clean => { clean::clean(); } Commands::Restore => { - restore::restore(); + // restore::restore(); + eprintln!("function disabled"); } - Commands::Clone(c) => { - clone::clone(&c.path, c.hooks, &c.compression, &c.mode); + Commands::Clone(_) => { + // clone::clone(&c.path, c.hooks, &c.compression, &c.mode); + eprintln!("function disabled"); } } } diff --git a/src/pull.rs b/src/pull.rs index 47f30ac8feb2b2f68c7b9e5b523fa282d009a6f3..b6ff296711f9acce9ab1aaf1b42fc6d474d4733b 100644 --- a/src/pull.rs +++ b/src/pull.rs @@ -2,285 +2,254 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later -use crate::commit; -use crate::mount::file_diff; -use crate::push; -use colored::Colorize; -use std::path::PathBuf; -use std::process::{exit, Command, Stdio}; +// use crate::commit; +// use crate::mount::file_diff; +// use crate::push; +// use colored::Colorize; +// use std::path::PathBuf; +// use std::process::{exit, Command, Stdio}; -/// Function that gets the backup borg folder path used to restore or .borg -/// folder in case that the pull command fails -/// -/// # Arguments -/// - ` borg_folder` : Path to .brg folder of the current project -/// # Return -/// backup borg folder path used to restore or .borg -/// folder in case that the pull command fails. It will be located in -/// .tmp/<PROJECT_DIR>_bkp folder. Where <PROJECT_DIR> is the folder name -/// containging our project -pub(crate) fn get_savefolder(borg_folder: &PathBuf) -> PathBuf { - let mut save_dir = file_diff::get_tmp_folder(borg_folder); - let folder_name = borg_folder - .parent() - .unwrap() - .file_name() - .unwrap() - .to_str() - .unwrap(); - save_dir.push(format!("{}_bkp", folder_name)); - save_dir -} +// /// Function that gets the backup borg folder path used to restore or .borg +// /// folder in case that the pull command fails +// /// +// /// # Arguments +// /// - ` borg_folder` : Path to .brg folder of the current project +// /// # Return +// /// backup borg folder path used to restore or .borg +// /// folder in case that the pull command fails. It will be located in +// /// .tmp/<PROJECT_DIR>_bkp folder. Where <PROJECT_DIR> is the folder name +// /// containging our project +// pub(crate) fn get_savefolder(borg_folder: &PathBuf) -> PathBuf { +// let mut save_dir = file_diff::get_tmp_folder(borg_folder); +// let folder_name = borg_folder +// .parent() +// .unwrap() +// .file_name() +// .unwrap() +// .to_str() +// .unwrap(); +// save_dir.push(format!("{}_bkp", folder_name)); +// save_dir +// } -/// Function that removes the backup folder (`save_dir`) in the tmp directory if it exists -/// # Argument -/// - `save_dir`: The backup folder inside the .tmp directory -fn check_and_remove_dir(save_dir: &PathBuf) { - if !save_dir.is_dir() { - return (); - } - let anwser = push::user_question(&format!( - "The backup folder {} already exists, Erase it with you're current .borg folder for backup", - save_dir.display() - )); - if !anwser { - println!("{}: Exiting !", "info".blue()); - exit(0); - } - match std::fs::remove_dir_all(save_dir) { - Err(e) => { - eprintln!( - "{}: Unable to remove {}. {}", - "error".red(), - save_dir.display(), - e - ); - exit(1); - } - Ok(_) => (), - }; -} +// /// Function that removes the backup folder (`save_dir`) in the tmp directory if it exists +// /// # Argument +// /// - `save_dir`: The backup folder inside the .tmp directory +// fn check_and_remove_dir(save_dir: &PathBuf) { +// if !save_dir.is_dir() { +// return (); +// } +// let anwser = push::user_question(&format!( +// "The backup folder {} already exists, Erase it with you're current .borg folder for backup", +// save_dir.display() +// )); +// if !anwser { +// println!("{}: Exiting !", "info".blue()); +// exit(0); +// } +// match std::fs::remove_dir_all(save_dir) { +// Err(e) => { +// eprintln!( +// "{}: Unable to remove {}. {}", +// "error".red(), +// save_dir.display(), +// e +// ); +// exit(1); +// } +// Ok(_) => (), +// }; +// } -/// Function that will remove almost all the content of the .borg folder -/// it only keeps .gblkconfig if it exists -/// # Arguments -/// - `borg_folder` : path to the .borg folder -fn save_and_clean_borg_folder(borg_folder: &PathBuf) { - let save_dir = get_savefolder(borg_folder); - println!( - "{}: Saving current .borg repositoy into {} for backup.\n - If everything works, you can remove it with the command {}.\n - If nothing works anymore, you can restore it with {}", - "info".blue(), - &save_dir.display(), - "gblk clean".green(), - "gblk restore".green() - ); - println!("{}", &save_dir.display()); - // check if the folder exits, removes it with the user permission - check_and_remove_dir(&save_dir); - match std::fs::create_dir(&save_dir) { - Err(e) => { - eprintln!( - "{}: Unable to create {}. {}", - "error".red(), - &save_dir.display(), - e - ); - exit(1); - } - Ok(_) => (), - } - let paths = std::fs::read_dir(borg_folder).unwrap(); - for p in paths { - let pa = p.unwrap().path(); - let name = pa.file_name().unwrap().to_str().unwrap(); - let mut destination = save_dir.to_owned(); - destination.push(name); - match name { - ".gblkconfig" | "config" => { - std::fs::copy(&pa, &destination).expect(&format!( - "{}: Unable to copy {} to {}. Your .borg folder may be corrupted, you can restor it wiht the command {}", - "error".red(), - &pa.display(), - &destination.display(), - "gblk restore".green() - )); - } - _ => { - std::fs::rename(&pa, &destination).expect(&format!( - "{}: Unable to move {} to {} Your .borg folder may be corrupted, you can restor it wiht the command {}", - "error".red(), - &pa.display(), - &destination.display(), - "gblk restore".green() - )); - } - } - } -} +// /// Function that will remove almost all the content of the .borg folder +// /// it only keeps .gblkconfig if it exists +// /// # Arguments +// /// - `borg_folder` : path to the .borg folder +// fn save_and_clean_borg_folder(borg_folder: &PathBuf) { +// let save_dir = get_savefolder(borg_folder); +// println!( +// "{}: Saving current .borg repositoy into {} for backup.\n - If everything works, you can remove it with the command {}.\n - If nothing works anymore, you can restore it with {}", +// "info".blue(), +// &save_dir.display(), +// "gblk clean".green(), +// "gblk restore".green() +// ); +// println!("{}", &save_dir.display()); +// // check if the folder exits, removes it with the user permission +// check_and_remove_dir(&save_dir); +// match std::fs::create_dir(&save_dir) { +// Err(e) => { +// eprintln!( +// "{}: Unable to create {}. {}", +// "error".red(), +// &save_dir.display(), +// e +// ); +// exit(1); +// } +// Ok(_) => (), +// } +// let paths = std::fs::read_dir(borg_folder).unwrap(); +// for p in paths { +// let pa = p.unwrap().path(); +// let name = pa.file_name().unwrap().to_str().unwrap(); +// let mut destination = save_dir.to_owned(); +// destination.push(name); +// match name { +// ".gblkconfig" | "config" => { +// std::fs::copy(&pa, &destination).expect(&format!( +// "{}: Unable to copy {} to {}. Your .borg folder may be corrupted, you can restor it wiht the command {}", +// "error".red(), +// &pa.display(), +// &destination.display(), +// "gblk restore".green() +// )); +// } +// _ => { +// std::fs::rename(&pa, &destination).expect(&format!( +// "{}: Unable to move {} to {} Your .borg folder may be corrupted, you can restor it wiht the command {}", +// "error".red(), +// &pa.display(), +// &destination.display(), +// "gblk restore".green() +// )); +// } +// } +// } +// } -/// Function that check if `path_str` is an existing directory. If it exists, -/// return it else raise an error -/// # Arguments -/// - `path_str`: A path in string form -/// # Return -/// The pathbuf object of `path_str` -fn check_ok(path_str: &str) -> PathBuf { - let path = PathBuf::from(path_str); - if !path.is_dir() { - eprintln!( - "{}: {} is not a directory !", - "error:".red(), - path.display() - ); - exit(1) - } else { - return path; - } -} +// /// Function that check if `path_str` is an existing directory. If it exists, +// /// return it else raise an error +// /// # Arguments +// /// - `path_str`: A path in string form +// /// # Return +// /// The pathbuf object of `path_str` +// fn check_ok(path_str: &str) -> PathBuf { +// let path = PathBuf::from(path_str); +// if !path.is_dir() { +// eprintln!( +// "{}: {} is not a directory !", +// "error:".red(), +// path.display() +// ); +// exit(1) +// } else { +// return path; +// } +// } -/// Get the borg base directory -/// -/// # Description -/// Get the directory defined with BORG_BASE_DIR env variable or the directory -/// defined in HOME variable -/// -/// # Return -/// The borg base directory -fn get_base_dir() -> PathBuf { - let base_dir = std::env::var("BORG_BASE_DIR"); - match base_dir { - Ok(dir) => check_ok(&dir), - Err(_) => { - let base_dir = std::env::var("HOME"); - match base_dir { - Ok(dir) => check_ok(&dir), - Err(_) => { - eprintln!("{}: HOME environment variable not set !", "error".red()); - exit(1); - } - } - } - } -} +// /// Get the borg base directory +// /// +// /// # Description +// /// Get the directory defined with BORG_BASE_DIR env variable or the directory +// /// defined in HOME variable +// /// +// /// # Return +// /// The borg base directory +// fn get_base_dir() -> PathBuf { +// let base_dir = std::env::var("BORG_BASE_DIR"); +// match base_dir { +// Ok(dir) => check_ok(&dir), +// Err(_) => { +// let base_dir = std::env::var("HOME"); +// match base_dir { +// Ok(dir) => check_ok(&dir), +// Err(_) => { +// eprintln!("{}: HOME environment variable not set !", "error".red()); +// exit(1); +// } +// } +// } +// } +// } -/// Get the borg config directory -/// -/// # Description -/// Get the directory defined with BORG_BASE_DIR env variable or the directory -/// defined in HOME variable -/// -/// # Return -/// The borg base directory -fn get_config_dir() -> PathBuf { - let mut config = get_base_dir(); - config.push(".config"); - let new_config = if !std::env::var("BORG_BASE_DIR").is_ok() { - let mut new_config = match std::env::var("XDG_CONFIG_HOME") { - Ok(p) => check_ok(&p), - Err(_) => config, - }; - new_config.push("borg"); - new_config - } else { - let config_path = match std::env::var("BORG_CONFIG_DIR") { - Ok(p) => check_ok(&p), - Err(_) => { - config.push("borg"); - config - } - }; - config_path - }; - if !new_config.is_dir() { - eprintln!("{}: Failed to get borg config dir", &new_config.display()); - exit(1); - } - new_config -} +// /// Get the borg config directory +// /// +// /// # Description +// /// Get the directory defined with BORG_BASE_DIR env variable or the directory +// /// defined in HOME variable +// /// +// /// # Return +// /// The borg base directory +// fn get_config_dir() -> PathBuf { +// let mut config = get_base_dir(); +// config.push(".config"); +// let new_config = if !std::env::var("BORG_BASE_DIR").is_ok() { +// let mut new_config = match std::env::var("XDG_CONFIG_HOME") { +// Ok(p) => check_ok(&p), +// Err(_) => config, +// }; +// new_config.push("borg"); +// new_config +// } else { +// let config_path = match std::env::var("BORG_CONFIG_DIR") { +// Ok(p) => check_ok(&p), +// Err(_) => { +// config.push("borg"); +// config +// } +// }; +// config_path +// }; +// if !new_config.is_dir() { +// eprintln!("{}: Failed to get borg config dir", &new_config.display()); +// exit(1); +// } +// new_config +// } -/// This function aims to get the borg security dir -/// -/// # Description -/// Get the borg security folder defined by the BORG_SECURITY_DIR env variable -/// or get the borg_config_dir/security path -/// # Return -/// The path to the borg security dir -fn get_security_dir() -> PathBuf { - let security_dir = std::env::var("BORG_SECURITY_DIR"); - match security_dir { - Ok(dir) => check_ok(&dir), - Err(_) => { - let mut path = get_config_dir(); - path.push("security"); - return path; - } - } -} +// /// This function aims to get the borg security dir +// /// +// /// # Description +// /// Get the borg security folder defined by the BORG_SECURITY_DIR env variable +// /// or get the borg_config_dir/security path +// /// # Return +// /// The path to the borg security dir +// fn get_security_dir() -> PathBuf { +// let security_dir = std::env::var("BORG_SECURITY_DIR"); +// match security_dir { +// Ok(dir) => check_ok(&dir), +// Err(_) => { +// let mut path = get_config_dir(); +// path.push("security"); +// return path; +// } +// } +// } -/// Get the timestamp manifest for the current borg project -/// # Arguments -/// - `security_dir`: The borg security folder -/// # Return -/// A file corresponding to the timestamp manifest of the project folder -fn get_manifest_timestamp(security_dir: PathBuf) -> PathBuf { - let current_id = push::get_project_id(); - let mut security_dir = security_dir; - security_dir.push(current_id); - security_dir.push("manifest-timestamp"); - if !security_dir.is_file() { - eprintln!( - "{}: {} is not a file !", - "error".red(), - &security_dir.display() - ); - exit(1); - }; - security_dir -} -/// Function that remove the borg manifest-timestamp for the current borg project -fn remove_manifest_timestamp() { - let security_dir = get_security_dir(); - let manifest = get_manifest_timestamp(security_dir); - std::fs::remove_file(&manifest).expect(&format!( - "{}: Unable to delete {}", - "error".red(), - &manifest.display() - )); -} +// /// Function that removes .borg cache +// /// # Arguments +// /// - `borg_folder`: The .borg folder of the current project +// fn borg_delete_cache(borg_folder: &PathBuf) { +// let args = vec!["delete", "--cache-only", borg_folder.to_str().unwrap()]; +// let mut output = Command::new("borg") +// .args(&args) +// .stdout(Stdio::inherit()) +// .stdin(Stdio::inherit()) +// .spawn() +// .unwrap(); +// match output.wait() { +// Err(e) => { +// eprintln!("{}: borg terminaned with an error: {}", "error".red(), e); +// exit(1); +// } +// Ok(_) => (), +// } +// } -/// Function that removes .borg cache -/// # Arguments -/// - `borg_folder`: The .borg folder of the current project -fn borg_delete_cache(borg_folder: &PathBuf) { - let args = vec!["delete", "--cache-only", borg_folder.to_str().unwrap()]; - let mut output = Command::new("borg") - .args(&args) - .stdout(Stdio::inherit()) - .stdin(Stdio::inherit()) - .spawn() - .unwrap(); - match output.wait() { - Err(e) => { - eprintln!("{}: borg terminaned with an error: {}", "error".red(), e); - exit(1); - } - Ok(_) => (), - } -} - -/// Create a push the tar achive on the selected remote path -/// # Arguments -/// - `remote`: The name of a remote -pub fn pull(remote: &str) -> () { - let (adress, url) = push::get_adress_and_url(remote); - let (borg_folder, _) = commit::check_path(); - let borg_folder = borg_folder.canonicalize().unwrap(); - push::check_dest_and_copy(&borg_folder, &url, &adress); - let remote_dir = push::get_remote_dir(&url); - push::handle_existing_remote_dir(&remote_dir, &adress, "pull"); - save_and_clean_borg_folder(&borg_folder); - push::copy_file(&borg_folder, &remote_dir, &adress, "pull"); - remove_manifest_timestamp(); - borg_delete_cache(&borg_folder); -} +// /// Create a push the tar achive on the selected remote path +// /// # Arguments +// /// - `remote`: The name of a remote +// pub fn pull(remote: &str) -> () { +// let (adress, url) = push::get_adress_and_url(remote); +// let (borg_folder, _) = commit::check_path(); +// let borg_folder = borg_folder.canonicalize().unwrap(); +// push::check_dest_and_copy(&borg_folder, &url, &adress); +// // let remote_dir = push::get_remote_dir(&url); +// // push::handle_existing_remote_dir(&remote_dir, &adress, "pull"); +// // save_and_clean_borg_folder(&borg_folder); +// // push::export_tar(&borg_folder, &remote_dir, &adress, "pull"); +// // remove_manifest_timestamp(); +// // borg_delete_cache(&borg_folder); +// } diff --git a/src/push.rs b/src/push.rs index 7149fcd6af99edfba2b08078e830154e437099e1..11ce3641a151559faae666d96e3e01868474d162 100644 --- a/src/push.rs +++ b/src/push.rs @@ -3,320 +3,95 @@ // SPDX-License-Identifier: AGPL-3.0-or-later use crate::commit; -use crate::configt; -use crate::list; +use crate::mount; use crate::remote; use colored::Colorize; -use regex::Regex; -use std::io::{self, Write}; +use std::fs; +use std::os::unix::fs::PermissionsExt; use std::path::PathBuf; use std::process::{exit, Command, Stdio}; -/// Get the file that will contains the archive listing in it -/// # Return -/// The path of the file archive_list inside the .borg repository of the -/// current project -fn get_list_file() -> PathBuf { - let (mut borg_folder, _) = commit::check_path(); - borg_folder.push("archive_list"); - borg_folder -} +const COMPRESSION: [&str; 6] = ["gzip", "bzip2", "xz", "zstd", "lz4", "none"]; -/// Get the location were the remote archiive list ill be stored -/// # Return -/// The path of the file archive_list_remote inside the .borg repository of the -/// current project -fn get_remote_list_file() -> PathBuf { - let (mut borg_folder, _) = commit::check_path(); - borg_folder.push("archive_list_remote"); - borg_folder -} - -/// Get the file that contains borg config +/// Function that check if a file exist on the local filesystem +/// # Arguments +/// - `remote_dir`: The remote dir located by the remote /// # Return -/// The path of the file config inside the .borg repository of the -/// current project -fn get_config_file() -> PathBuf { - let (mut borg_folder, _) = commit::check_path(); - borg_folder.push("config"); - borg_folder +/// true if the `remote_dir` is a directory, false else +fn check_dir_exist_local(remote_dir: &PathBuf) -> bool { + remote_dir.is_dir() } -/// Write the content `content`into a file `mfile` +/// Function that check if a file with a glob pattern exist on the local filesystem /// # Arguments -/// - `mfile`: The file to write -/// - `content`: The content to write in the file -fn write_file(mfile: &PathBuf, content: &str) { - match std::fs::write(mfile, content) { - Err(e) => { - eprintln!( - "{}: Unable to write file '{}' - {}", - "error".red(), - mfile.to_str().unwrap().yellow(), - e.to_string() - ) - } - Ok(_) => (), - }; -} - -/// Create archive_list file with theresults of gblk lists +/// - `remote_file`: The remote file located inside the remote /// # Return -/// The path of the file archive_list inside the .borg repository of the -/// current project -fn create_archive_list() -> PathBuf { - let output = list::borg_list_launcher(0, 0, ""); - let content = match output.status.code().unwrap() { - 0 => format!("{}", String::from_utf8(output.stdout).unwrap()), - num => { - eprintln!("{}", String::from_utf8(output.stderr).unwrap()); - exit(num); - } - }; - let archive_file = get_list_file(); - write_file(&archive_file, &content); - archive_file +/// true if the `remote_file` is at least a file, false else +fn check_glob_exist_local(remote_file: &PathBuf) -> Option<PathBuf> { + let mut filenames: Vec<String> = Vec::new(); + filenames.push( + remote_file + .file_name() + .unwrap() + .to_str() + .unwrap() + .to_string(), + ); + let walker = + globwalk::GlobWalkerBuilder::from_patterns(remote_file.parent().unwrap(), &filenames) + .max_depth(1) + .follow_links(false) + .build() + .unwrap() + .into_iter() + .filter_map(Result::ok) + .map(|x| x.path().to_path_buf()) + .collect::<Vec<_>>(); + if walker.len() > 0 { + Some(walker.get(0).unwrap().to_path_buf()) + } else { + None + } } -/// function that deletes a given file +/// Function that checks if a glob file exists and return the first path found +/// if it's the case +/// /// # Arguments -/// - `my_file`: The file to remove -fn delete_file(my_file: &PathBuf) { - match std::fs::remove_file(&my_file) { - Err(e) => { - eprintln!( - "{}: unable to remove '{}' - {}", - "error".red(), - my_file.display(), - e - ); - exit(1); - } - Ok(_) => (), - }; -} - -/// Gets the content of a file inside the local filesystem -/// # Arguments: -/// - `remote_dir`: The path of a file inside the local filesystem -/// - `mfile`: The file for which we want to get the content -/// # Results: -/// return the content of the file in the local filesystem -pub fn get_content_dir_file_locally(remote_dir: &PathBuf, mfile: &str) -> String { - let mut remote_file = remote_dir.to_owned(); - remote_file.push(mfile); - match std::fs::read_to_string(&remote_file) { - Err(e) => { - eprintln!( - "{}: Unable to read {}. {}", - "error".red(), - remote_file.display(), - e - ); - exit(1); - } - Ok(content) => content, +/// - `remote_file`: The remote glob located by the remote +/// - `adress`: The adress of the remote folder +fn check_glob_file_exists(remote_file: &PathBuf, adress: &str) -> Option<PathBuf> { + if adress == "file" { + check_glob_exist_local(remote_file) + } else { + check_glob_file_exist_remote(remote_file, adress) } } -/// Get the content of a file in a remote server +/// Function that check if a dir exist on a remote filesystem /// # Arguments -/// - remote_dir: A path corresponding to a remote dir -/// - adress: The adress of the remove sever -/// - mfile: The file for which we want to recover the content +/// - `remote_dir`: The remote dir located by the remote +/// - `adress`: The adress of the remote folder /// # Return -/// The content of the file `mfile` in the remote server -pub fn get_content_dir_file_remotly(remote_dir: &PathBuf, adress: &str, mfile: &str) -> String { - let mut remote_file = remote_dir.to_owned(); - remote_file.push(mfile); - let args = vec![adress, "cat", remote_file.to_str().unwrap()]; +/// true if the `remote_dir` is a directory, false else +fn check_glob_file_exist_remote(remote_tar: &PathBuf, adress: &str) -> Option<PathBuf> { + let args = vec![adress, "ls", remote_tar.to_str().unwrap()]; let output = Command::new("ssh") .args(&args) .stdout(Stdio::piped()) - .stdin(Stdio::inherit()) .output() .unwrap(); - // extract the raw bytes that we captured and interpret them as a string - let stdout = String::from_utf8(output.stdout).unwrap(); - if stdout.len() == 0 { - eprintln!("{}: The file {} is empty or doesn't exits in {}. Maybe the directory is not a borg folder.", - "error".red(), mfile, remote_dir.display()); - exit(1); - } - stdout -} - -/// Get the content of a file `mfile` located into either remotely or locally -/// # Arguments -/// - remote_dir: A path corresponding to the remote dir -/// - adress: The adress of the remove sever -/// - mfile: The file for which we want to recover the content -/// # Return -/// The content of the file `mfile` in the remote server or in the local filesystem -fn get_content_file(remote_dir: &PathBuf, adress: &str, mfile: &str) -> String { - if adress != "file" { - return get_content_dir_file_remotly(remote_dir, adress, mfile); - } - return get_content_dir_file_locally(remote_dir, mfile); -} - -/// Get the contained into the content string -/// # Arguments -/// - `content` : The content of a config file -/// # Return -/// The id inside the string corresponding to a borg config file -fn get_id(content: &str) -> String { - let re = Regex::new(r"id = ([a-z0-9]*)\n").unwrap(); - let res = re.captures(content); - let my_id = match res { - None => { - eprintln!("{}: No id found", "error".red()); - exit(1); - } - Some(e) => e[1].to_owned(), - }; - my_id -} - -/// Get the current project id -/// # Return -/// The id inside .borg/config file -pub(crate) fn get_project_id() -> String { - let config_file = get_config_file(); - let current_config = match std::fs::read_to_string(config_file) { - Err(_) => { - eprintln!("{}: Unable to read current config file !", "error".red()); - exit(1); - } - Ok(e) => e, - }; - let current_id = get_id(¤t_config); - current_id -} - -/// compare the id of the current config with the id of the remote config -/// # Arguments -/// - `remote_dir`: The path to the remote directory -/// - `adress`: The location of the remote directory -/// # Return -/// - A boolean, true if distant and local id are the same, false else, -/// - A string: the current project id -/// - Another string: The remote project id -fn compare_id(remote_dir: &PathBuf, adress: &str) -> (bool, String, String) { - let current_id = get_project_id(); - let distant_id = get_id(&get_content_file(remote_dir, adress, "config")); - (current_id == distant_id, current_id, distant_id) -} - -/// Asks the user a question and get the answer -/// # Arguments: -/// - `question`: The question asked to a user -/// # Return -/// True if the user agree, false else -pub fn user_question(question: &str) -> bool { - print!("{} ? [y/n] : ", question); - io::stdout().flush().unwrap(); - let mut user_input = String::new(); - match std::io::stdin().read_line(&mut user_input) { - Ok(_) => (), - Err(_) => { - eprintln!("{}: Unable to read user input", "error".red()); - exit(1); + let str_paths = String::from_utf8(output.stdout).unwrap(); + let paths = str_paths.split_ascii_whitespace().collect::<Vec<&str>>(); + if paths.len() > 0 { + if paths.get(0).unwrap().len() > 0 { + Some(PathBuf::from(paths.get(0).unwrap())) + } else { + None } - }; - let user_input = user_input.trim(); - user_input.to_lowercase() == "y" -} - -/// Create a file containing the archives located -/// # Arguments -/// - `remote_dir`: The path to the remote directory -/// - `adress`: The location of the remote directory -/// # Return -/// The path to the destination archive list -fn create_destination_archive_list(remote_dir: &PathBuf, adress: &str) -> PathBuf { - let content = get_content_file(remote_dir, adress, "archive_list"); - let remote_list_file = get_remote_list_file(); - write_file(&remote_list_file, &content); - remote_list_file -} - -/// Function that show differences between local_archive_list and remote_archive_list -/// # Arguments -/// - `local_archive_list`: Files containing archive list defined in current -/// borg folder -/// - `remote_archive_list`: Files containing archive list defined remotly -/// - `cmd`: The kind of command executed either pull or push -fn show_diff_archive_list(local_archive_list: &PathBuf, remote_archive_list: &PathBuf, cmd: &str) { - let args = if cmd == "push" { - vec![remote_archive_list, local_archive_list] } else { - vec![local_archive_list, remote_archive_list] - }; - let mut output = Command::new("delta") - .args(&args) - .stdout(Stdio::inherit()) - .stdin(Stdio::inherit()) - .spawn() - .unwrap(); - match output.wait() { - Err(e) => { - eprintln!("{}: delta terminaned with an error: {}", "error".red(), e); - exit(1); - } - Ok(_) => { - let output = Command::new("delta") - .args(&args) - .stdout(Stdio::piped()) - .output() - .unwrap(); - let s = String::from_utf8(output.stdout).unwrap(); - if s.len() == 0 { - println!( - "{}: No differences between remote and current archive lists. Skipping {} command.", - "info".blue(), - cmd.green() - ); - exit(0); - } - } - }; -} - -/// Creates current and remote list files and display their differences using delta -/// -/// # Description: -/// This function creates current and remote list files and display their differences using delta. -/// Then it remove both files -/// -/// # Arguments -/// - `cmd`: A command name, it should be `push` or `pull` -/// - `remote_dir`: The remote dir located by the remote -/// - `adress`: The location of the remote folder -fn create_and_show_diff(cmd: &str, remote_dir: &PathBuf, adress: &str) { - let remote_archive_list = create_destination_archive_list(remote_dir, adress); - let local_archive_list = create_archive_list(); - show_diff_archive_list(&local_archive_list, &remote_archive_list, cmd); - delete_file(&local_archive_list); - delete_file(&remote_archive_list); -} - -/// Function that check if a file exist on the local filesystem -/// # Arguments -/// - `remote_dir`: The remote dir located by the remote -/// # Return -/// true if the `remote_dir` is a directory, false else -fn check_dir_exist_local(remote_dir: &PathBuf) -> bool { - remote_dir.is_dir() -} - -/// Function that check if a file exist on the local filesystem -/// # Arguments -/// - `remote_file`: The remote file located inside the remote -/// # Return -/// true if the `remote_dir` is a directory, false else -fn check_file_exist_local(remote_file: &PathBuf) -> bool { - remote_file.is_file() + None + } } /// Function that check if a dir exist on a remote filesystem @@ -342,20 +117,6 @@ fn check_file_exist_remote(remote_tar: &PathBuf, adress: &str) -> bool { } } -/// Function that check if a file exist on a remote or the local filesystem -/// # Arguments -/// - `remote_dir`: The remote dir located by the remote -/// - `adress`: The adress of the remote folder -/// # Return -/// true if the `remote_dir` is a directory, false else -pub(crate) fn check_file_exist(remote_dir: &PathBuf, adress: &str) -> bool { - if adress == "file" { - check_file_exist_local(remote_dir) - } else { - check_file_exist_remote(remote_dir, adress) - } -} - /// Function that check if a dir exist on a remote or the local filesystem /// # Arguments /// - `remote_dir`: The remote dir located by the remote @@ -370,57 +131,50 @@ pub(crate) fn check_dir_exist(remote_dir: &PathBuf, adress: &str) -> bool { } } -/// Function that performs some checks before pushing or pulling a borg archive -/// -/// # Description -/// This function perform several checks for push and pull commands. -/// - Pull command: -/// 1. Checks if the remote directory exists. If it doesn't stops the pull -/// 2. Checks if the remote and the local borg id are the same. Stops the pull -/// if they are different -/// 3. Show the differences between the remote and the local archive lists and ask the user if he -/// wants to continue the pull -/// - Push Command -/// 1. Checks if the remote directory exists. If it doesn't skip checks 2 and -/// 3 and perform push command -/// 2. Checks if the remote and the local borg id are the same. Stops the push -/// if they are different -/// 3. Show the differences between the remote and the local archive lists and ask the user if he -/// wants to continue the push +/// Function that checks if the archive file to push/pull already exists /// /// # Arguments /// - `cmd`: A command name, it should be `push` or `pull` -/// - `remote_dir`: The remote dir located by the remote +/// - `remote_file`: The remote archive file located by the remote /// - `adress`: The location of the remote folder -pub(crate) fn handle_existing_remote_dir(remote_dir: &PathBuf, adress: &str, cmd: &str) { - if !check_dir_exist(remote_dir, adress) { - if cmd == "push" { - return (); - } else { - eprintln!( - "{}: remote dir {} not found", - "error".red(), - format!("{}:{}", adress, remote_dir.display()) - ); - exit(1); - } - } - let (same_id, current_id, remote_id) = compare_id(remote_dir, adress); - if !same_id { - eprintln!("{}: remote ({}) and current ({}) borg id are different. Maybe the remote borg folder doesn't come from your local project !", - "error".red(), - remote_id, - current_id); - exit(1); - } - create_and_show_diff(cmd, remote_dir, adress); - let answer = user_question(&format!( - "Do you want to continue the {} command", - cmd.green() - )); - if !answer { - // If the user want to abord the command, we abord it - exit(0); +/// +/// # Return +/// Path of the archive to pull/push +pub(crate) fn handle_existing_remote_file( + remote_file: &PathBuf, + adress: &str, + cmd: &str, +) -> PathBuf { + let archive = remote_file.file_stem().unwrap().to_str().unwrap(); + let filename_glob = remote_file + .parent() + .unwrap() + .join(format!("{}{}", archive, ".*")); + let distant_file = check_glob_file_exists(&filename_glob, &adress); + match cmd { + "push" => match distant_file { + None => return remote_file.to_owned(), + Some(file) => { + eprintln!( + "{}: A file with the same archive name exists {}, {}", + "error".red(), + file.display(), + "remove it manually if you wish to proceed !" + ); + exit(1); + } + }, + _ => match distant_file { + None => { + eprintln!( + "{}: The archive {} wasn't found on the remote", + "error".red(), + archive + ); + exit(1) + } + Some(mfile) => return mfile, + }, } } @@ -515,72 +269,74 @@ pub(crate) fn check_dest_and_copy(borg_folder: &PathBuf, url: &PathBuf, adress: exit(1); } } +/// set write permission for user and read for other +/// +/// # Argument: +/// - `remote_file`: The file for which we want to change the permissions +fn set_good_permission(remote_file: &PathBuf) -> () { + let metadata = remote_file.metadata().unwrap(); + let mut permissions = metadata.permissions(); + permissions.set_mode(0o644); + fs::set_permissions(remote_file, permissions).unwrap(); +} -/// Function used to copy a tar archive into the current working directory +/// Function used to export a tar archive in the remote file in the current +/// filsesystem +/// /// # Arguments /// - `borg_folder`: Path to borg folder -/// - `remote_dir`: Path where the borg folder will be copied -/// - `adress`: to location of the `url` path, 'file' for a local file -/// - `cmd`: puhs or pull -pub(crate) fn copy_file( - borg_folder: &PathBuf, - remote_dir: &PathBuf, - adress: &str, - cmd: &str, -) -> () { - let remote_path = if adress != "file" { - format!("{}:{}", adress, remote_dir.display()) - } else { - remote_dir.to_str().unwrap().to_string() +/// - `remote_file`: Path where the archive file will be stored +/// - `archive`: The archive name +fn export_tar_locally(borg_folder: &PathBuf, remote_file: &PathBuf, archive: &str) { + let borg_archive = format!( + "{}::{}", + borg_folder.canonicalize().unwrap().to_str().unwrap(), + archive + ); + let args = vec!["export-tar", &borg_archive, remote_file.to_str().unwrap()]; + let mut output: std::process::Child = Command::new("borg") + .args(&args) + .stdout(Stdio::inherit()) + .stdin(Stdio::inherit()) + .spawn() + .unwrap(); + let ecode = match output.wait() { + Err(e) => { + eprintln!( + "{}: borg export-tar returned an error: {} !", + "error".red(), + e + ); + exit(1); + } + Ok(r) => r, }; - - let tmp = if cmd == "pull" || cmd == "clone" { - format!("{}/", &remote_path) - } else { - format!("{}/", &borg_folder.display()) + match ecode.code().unwrap() { + 0 => (), + num => { + if remote_file.is_file() { + fs::remove_file(&remote_file).unwrap(); + } + exit(num); + } }; + set_good_permission(remote_file); +} - let args = if cmd == "pull" { - vec![ - "-a", - "--info=progress2", - "--human-readable", - "--exclude=config", - "--exclude=.gblkconfig", - "--exclude=archive_list", - "--exclude=archive_list_remote", - &tmp, - borg_folder.to_str().unwrap(), - ] - } else if cmd == "clone" { - vec![ - "-a", - "--info=progress2", - "--human-readable", - "--exclude=.gblkconfig", - "--exclude=archive_list", - "--exclude=archive_list_remote", - &tmp, - borg_folder.to_str().unwrap(), - ] - } else { - vec![ - "-a", - "--info=progress2", - "--human-readable", - "--exclude=.gblkconfig", - "--exclude=hints*", - "--exclude=index*", - "--exclude=integrity*", - &tmp, - &remote_path, - ] - }; - let local_archive_list = if cmd == "push" { - Some(create_archive_list()) - } else { - None - }; +/// Function used to export a tar archive in the remote file in the current +/// filsesystem +/// +/// # Arguments +/// - `borg_folder`: Path to borg folder +/// - `remote_file`: Path where the archive file will be stored +/// - `archive`: The archive name +/// - `adress`: The server location +fn export_tar_remotely(borg_folder: &PathBuf, remote_file: &PathBuf, archive: &str, adress: &str) { + let tmp_folder = mount::file_diff::get_tmp_folder(borg_folder); + let tmp_file = tmp_folder.join(remote_file.file_name().unwrap()); + export_tar_locally(borg_folder, &tmp_file, archive); + let remote_args = format!("{}:{}", adress, remote_file.to_str().unwrap()); + let args = vec![tmp_file.to_str().unwrap(), &remote_args]; let mut output = Command::new("rsync") .args(&args) .stdout(Stdio::inherit()) @@ -589,23 +345,10 @@ pub(crate) fn copy_file( .unwrap(); let ecode = match output.wait() { Err(e) => { - if cmd == "push" { - delete_file(&local_archive_list.unwrap()); - eprintln!("{}: rsync terminated with an error: {} !", "error".red(), e); - } else { - eprintln!( - "You .borg folder may be corrupted, restore it with {}", - "gblk restore".green() - ) - } + eprintln!("{}: rsync returned an error: {} !", "error".red(), e); exit(1); } - Ok(r) => { - if cmd == "push" { - delete_file(&local_archive_list.unwrap()); - } - r - } + Ok(r) => r, }; match ecode.code().unwrap() { 0 => (), @@ -613,32 +356,82 @@ pub(crate) fn copy_file( exit(num); } }; + fs::remove_file(tmp_file).unwrap(); +} + +/// Function used to export a tar archive in the remote file +/// # Arguments +/// - `borg_folder`: Path to borg folder +/// - `remote_file`: Path where the archive file will be stored +/// - `adress`: to location of the `url` path, 'file' for a local file +/// - `archive`: The archive name +fn export_tar(borg_folder: &PathBuf, remote_file: &PathBuf, adress: &str, archive: &str) -> () { + match adress { + "file" => export_tar_locally(borg_folder, remote_file, archive), + _ => export_tar_remotely(borg_folder, remote_file, archive, adress), + } +} + +/// Stop the program if the compression is not avalable +/// +/// # Arguments +/// - `compression`: The compression to use +fn compression_available(compression: &str) { + if !COMPRESSION.contains(&compression) { + eprintln!( + "{}: compression not defined ! Available compressions: {}", + "error".red(), + COMPRESSION.join(" ").yellow() + ); + exit(121); + } +} + +/// get the extention of the archive to recover +/// +/// # Arguments +/// - `compression`: The compression to use +fn extention_file(compression: &str) -> String { + match compression { + "gzip" => String::from(".tar.gz"), + "bzip2" => String::from(".tar.bz2"), + "xz" => String::from(".tar.xz"), + "zstd" => String::from(".tar.zstd"), + "lz4" => String::from(".tar.lz4"), + "none" => String::from(".tar"), + _ => String::from(".tar"), + } } -/// Function that return the name of the folder that will containg the content -/// of the .borg folder on the remote directory +/// Function that return path of the archive that will be exported/to get /// /// # Arguments /// - `url`: The path where the remote borg archive is or will be stored +/// - `archive`: The name of the archive to pull/push +/// - `compression`: The compression used /// # Return /// The path `url/borg_archive_<PROJECT_DIR>` where <PROJECT_DIR> is the name /// of the folder at the root of the project -pub(crate) fn get_remote_dir(url: &PathBuf) -> PathBuf { - let mut remote_dir = url.to_owned(); - let name_folder = configt::get_project_name(); - remote_dir.push(name_folder); - remote_dir +pub(crate) fn get_remote_file(url: &PathBuf, archive: &str, compression: &str) -> PathBuf { + compression_available(compression); + let mut remote_file = url.to_owned(); + let ext = extention_file(compression); + let filename = format!("{}{}", archive, ext); + remote_file.push(filename); + remote_file } /// Create a push the tar achive on the selected remote path /// # Arguments /// - `remote`: The name of a remote -pub fn push(remote: &str) -> () { +/// - `archive`: The name of the archive to push +/// - `compression`: The compression to use when exporting the archive +pub fn push(remote: &str, archive: &str, compression: &str) -> () { let (borg_folder, _) = commit::check_path(); let borg_folder = borg_folder.canonicalize().unwrap(); let (adress, url) = get_adress_and_url(remote); check_dest_and_copy(&borg_folder, &url, &adress); - let remote_dir = get_remote_dir(&url); - handle_existing_remote_dir(&remote_dir, &adress, "push"); - copy_file(&borg_folder, &remote_dir, &adress, "push"); + let remote_file = get_remote_file(&url, archive, compression); + let remote_file = handle_existing_remote_file(&remote_file, &adress, "push"); + export_tar(&borg_folder, &remote_file, &adress, &archive); } diff --git a/src/restore.rs b/src/restore.rs index c9b35104f14e99d0085d847f890f1e8dac6d3cc6..37417cd5b7ce98877b54e2569b379f18f4032a24 100644 --- a/src/restore.rs +++ b/src/restore.rs @@ -2,38 +2,36 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later -use crate::commit; -use crate::pull; -use crate::push; +// use crate::commit; +// use crate::pull; +// use crate::push; +// /// Function that will remove almost all the content of the .borg folder +// /// it only keeps .gblkconfig if it exists +// fn clean_borg_folder() { +// let (borg_folder, _) = commit::check_path(); +// let paths = std::fs::read_dir(borg_folder).unwrap(); +// for p in paths { +// let pa = p.unwrap().path(); +// let name = pa.file_stem().unwrap().to_str().unwrap(); +// match name { +// "data" => { +// std::fs::remove_dir_all(pa).unwrap(); +// } +// ".gblkconfig" | "config" => (), +// _ => { +// std::fs::remove_file(pa).unwrap(); +// } +// } +// } +// } -/// Function that will remove almost all the content of the .borg folder -/// it only keeps .gblkconfig if it exists -fn clean_borg_folder() { - let (borg_folder, _) = commit::check_path(); - let paths = std::fs::read_dir(borg_folder).unwrap(); - for p in paths { - let pa = p.unwrap().path(); - let name = pa.file_stem().unwrap().to_str().unwrap(); - match name { - "data" => { - std::fs::remove_dir_all(pa).unwrap(); - } - ".gblkconfig" | "config" => (), - _ => { - std::fs::remove_file(pa).unwrap(); - } - } - } -} - - -/// Retore the .borg directory using the folder .tmp/<PROJECT_DIR>_bkp exists -/// Where PROJECT_DIR is the name of the folder at the root of your project -pub fn restore() { - let (borg_folder, _) = commit::check_path(); - let borg_folder = borg_folder.canonicalize().unwrap(); - let save_dir = pull::get_savefolder(&borg_folder); - clean_borg_folder(); - push::copy_file(&borg_folder, &save_dir, "file", "pull"); -} +// /// Retore the .borg directory using the folder .tmp/<PROJECT_DIR>_bkp exists +// /// Where PROJECT_DIR is the name of the folder at the root of your project +// pub fn restore() { +// let (borg_folder, _) = commit::check_path(); +// let borg_folder = borg_folder.canonicalize().unwrap(); +// let save_dir = pull::get_savefolder(&borg_folder); +// clean_borg_folder(); +// // push::export_tar(&borg_folder, &save_dir, "file", "pull"); +// }