check if directory to clone is empty
This commit is contained in:
parent
20926514d2
commit
39d1032c14
@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use clap::Values;
|
use clap::Values;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use crate::utils::api::ApiProps;
|
use crate::utils::api::ApiProps;
|
||||||
|
use crate::utils::read::read_folder;
|
||||||
use crate::global::global::{DIR_PATH, set_dir_path};
|
use crate::global::global::{DIR_PATH, set_dir_path};
|
||||||
use crate::services::api::ApiError;
|
use crate::services::api::ApiError;
|
||||||
use crate::services::req_props::{ReqProps, ObjProps};
|
use crate::services::req_props::{ReqProps, ObjProps};
|
||||||
@ -80,9 +81,17 @@ pub fn clone(remote: Values<'_>) {
|
|||||||
// create folder
|
// create folder
|
||||||
if first_iter {
|
if first_iter {
|
||||||
if DirBuilder::new().create(ref_path.clone()).is_err() {
|
if DirBuilder::new().create(ref_path.clone()).is_err() {
|
||||||
eprintln!("fatal: directory already exist");
|
if let Ok(entries) = read_folder(ref_path.clone()) {
|
||||||
// destination path 'path' already exists and is not an empty directory.
|
if entries.len() != 0 {
|
||||||
//std::process::exit(1);
|
eprintln!("fatal: destination path '{}' already exists and is not an empty directory.", ref_path.display());
|
||||||
|
std::process::exit(1);
|
||||||
|
} else {
|
||||||
|
init::init();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("fatal: cannot open the destination directory");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
init::init();
|
init::init();
|
||||||
}
|
}
|
||||||
|
@ -17,27 +17,27 @@ pub fn init() {
|
|||||||
path.push(".nextsync");
|
path.push(".nextsync");
|
||||||
match builder.create(path.clone()) {
|
match builder.create(path.clone()) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(_) => println!("Error: cannot create directory"),
|
Err(_) => println!("Error: cannot create .nextsync"),
|
||||||
};
|
};
|
||||||
|
|
||||||
path.push("objects");
|
path.push("objects");
|
||||||
match builder.create(path.clone()) {
|
match builder.create(path.clone()) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(_) => println!("Error: cannot create directory"),
|
Err(_) => println!("Error: cannot create objects"),
|
||||||
};
|
};
|
||||||
path.pop();
|
path.pop();
|
||||||
|
|
||||||
path.push("HEAD");
|
path.push("HEAD");
|
||||||
match File::create(path.clone()) {
|
match File::create(path.clone()) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
Err(_) => println!("Error: cannot create HEAD"),
|
||||||
}
|
}
|
||||||
|
|
||||||
path.pop();
|
path.pop();
|
||||||
path.push("index");
|
path.push("index");
|
||||||
match File::create(path.clone()) {
|
match File::create(path.clone()) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
Err(_) => println!("Error: cannot create index"),
|
||||||
}
|
}
|
||||||
|
|
||||||
path.pop();
|
path.pop();
|
||||||
|
Loading…
Reference in New Issue
Block a user