diff --git a/src/pull.rs b/src/pull.rs index 46ff9b6de7fd0e8035ab4245de09ffefba11d9e5..ccdd0baaceebc47d6991ca429961617ca334d1fd 100644 --- a/src/pull.rs +++ b/src/pull.rs @@ -141,6 +141,13 @@ pub fn borg_list() -> Vec<String> { /// - `remote`: The remote folder to use /// - `archive`: The archive to pull fn pull_one_archive(remote: &str, archive: &str) { + if archive.contains(".tar") { + eprintln!( + "{}: The archive given must not have an extention ! Please retry without any extentions.", + "error".red() + ); + return (); + } let (adress, url) = push::get_adress_and_url(remote); let (borg_folder, _) = commit::check_path(); let borg_folder = borg_folder.canonicalize().unwrap(); @@ -149,7 +156,7 @@ fn pull_one_archive(remote: &str, archive: &str) { let borg_archives = borg_list(); if borg_archives.contains(&archive.to_string()) { eprintln!( - "{}: The archive {} is already defined in your local .borg folder. Skipping", + "{}: The archive {} is already defined in your local .borg folder. Nothing to do !", "warning".yellow(), archive.yellow() ); @@ -157,6 +164,7 @@ fn pull_one_archive(remote: &str, archive: &str) { } // check if the remote archive file exists let remote_file = push::handle_existing_remote_file(&tmp_remote, &adress, "pull"); + eprintln!("{}: Pulling archive {} !", "info".blue(), archive.yellow()); import_tar(&borg_folder, &remote_file, &adress, &archive) } @@ -167,7 +175,7 @@ fn pull_one_archive(remote: &str, archive: &str) { /// # Return /// A vector of archive fn get_local_archives(url: &PathBuf) -> Vec<String> { - let mut filenames: Vec<String> = vec![String::from("*.tar*")]; + let filenames: Vec<String> = vec![String::from("*.tar*")]; let walker = globwalk::GlobWalkerBuilder::from_patterns(url, &filenames) .max_depth(1) .follow_links(false) @@ -180,7 +188,15 @@ fn get_local_archives(url: &PathBuf) -> Vec<String> { if walker.len() > 0 { let mut res = walker .into_iter() - .map(|x| x.file_stem().unwrap().to_str().unwrap().to_string()) + .map(|x| { + x.file_stem() + .unwrap() + .to_str() + .unwrap() + .split('.') + .collect::<Vec<_>>()[0] + .to_string() + }) .collect::<Vec<String>>(); res.sort(); res.dedup(); @@ -205,11 +221,22 @@ fn get_remote_archives(url: &PathBuf, adress: &str) -> Vec<String> { .output() .unwrap(); let str_paths = String::from_utf8(output.stdout).unwrap(); - let paths = str_paths.split_ascii_whitespace().collect::<Vec<&str>>(); + let paths = str_paths + .split_ascii_whitespace() + .map(|x| PathBuf::from(x)) + .collect::<Vec<PathBuf>>(); if paths.len() > 0 { let mut archive_vec = paths .into_iter() - .map(|x| x.to_owned()) + .map(|x| { + x.file_stem() + .unwrap() + .to_str() + .unwrap() + .split('.') + .collect::<Vec<_>>()[0] + .to_owned() + }) .collect::<Vec<String>>(); archive_vec.sort(); archive_vec.dedup(); @@ -257,7 +284,7 @@ pub fn pull(remote: &str, archive: &Option<String>, all: bool) -> () { if !all { match archive { None => { - eprintln!("{}: Nothing to do !", "warning".yellow()); + eprintln!("{}: Nothing to do !. Give an archive name or the flag --all to pull every archives from the remote folder !", "warning".yellow()); return (); } Some(arc) => pull_one_archive(remote, arc),