Skip to content
Snippets Groups Projects
Verified Commit 418bcf98 authored by nfontrod's avatar nfontrod
Browse files

src/restore.rs: the current borg folder may need a clean, so cleans it

parent ec704414
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,34 @@ 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();
}
}
}
}
/// 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");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment