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

src/pull.rs src/push.rs: update of get_remote_dir

parent 0a13aedc
No related branches found
No related tags found
No related merge requests found
......@@ -273,7 +273,7 @@ pub fn pull(remote: &str) -> () {
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, &borg_folder);
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");
......
use crate::commit;
use crate::configt;
use crate::list;
use crate::remote;
use colored::Colorize;
......@@ -173,7 +174,6 @@ fn get_id(content: &str) -> String {
my_id
}
/// Get the current project id
/// # Return
/// The id inside .borg/config file
......@@ -204,7 +204,6 @@ fn compare_id(remote_dir: &PathBuf, adress: &str) -> (bool, String, String) {
(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
......@@ -307,7 +306,16 @@ fn check_dir_exist_local(remote_dir: &PathBuf) -> bool {
remote_dir.is_dir()
}
/// Function that check if a file exist on a remote filesystem
/// 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()
}
/// Function that check if a dir exist on a remote filesystem
/// # Arguments
/// - `remote_dir`: The remote dir located by the remote
/// - `adress`: The adress of the remote folder
......@@ -336,7 +344,21 @@ fn check_file_exist_remote(remote_tar: &PathBuf, adress: &str) -> bool {
/// - `adress`: The adress of the remote folder
/// # Return
/// true if the `remote_dir` is a directory, false else
fn check_dir_exist(remote_dir: &PathBuf, adress: &str) -> bool {
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
/// - `adress`: The adress of the remote folder
/// # Return
/// true if the `remote_dir` is a directory, false else
pub(crate) fn check_dir_exist(remote_dir: &PathBuf, adress: &str) -> bool {
if adress == "file" {
check_dir_exist_local(remote_dir)
} else {
......@@ -424,13 +446,19 @@ fn get_remote_path(remote: &str) -> String {
/// - `url`: A complete url path in adress:path form
/// # Return
/// A tuple containing the adress and the url
fn split_path(url: &str) -> (String, PathBuf) {
pub(crate) fn split_path(url: &str) -> (String, PathBuf) {
let res = url.split(":").collect::<Vec<&str>>();
if res.len() == 1 {
return (String::from("file"), PathBuf::from(url));
return (
String::from("file"),
PathBuf::from(url).canonicalize().unwrap(),
);
} else if res.len() == 2 {
if res[0].to_lowercase() == "file" {
return (String::from("file"), PathBuf::from(res[1]));
return (
String::from("file"),
PathBuf::from(res[1]).canonicalize().unwrap(),
);
}
return (res[0].to_owned(), PathBuf::from(res[1]));
}
......@@ -557,7 +585,6 @@ pub(crate) fn copy_file(
};
}
/// Function that return the name of the folder that will containg the content
/// of the .borg folder on the remote directory
///
......@@ -566,18 +593,9 @@ pub(crate) fn copy_file(
/// # 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, borg_folder: &PathBuf) -> PathBuf {
pub(crate) fn get_remote_dir(url: &PathBuf) -> PathBuf {
let mut remote_dir = url.to_owned();
let name_folder = format!(
"borg-archive_{}",
borg_folder
.parent()
.unwrap()
.file_stem()
.unwrap()
.to_str()
.unwrap()
);
let name_folder = configt::get_project_name();
remote_dir.push(name_folder);
remote_dir
}
......@@ -590,7 +608,7 @@ pub fn push(remote: &str) -> () {
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, &borg_folder);
let remote_dir = get_remote_dir(&url);
handle_existing_remote_dir(&remote_dir, &adress, "push");
copy_file(&borg_folder, &remote_dir, &adress, "push");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment