check if directory where the init command is clone is empty
This commit is contained in:
parent
39d1032c14
commit
d3592a5209
@ -80,21 +80,12 @@ pub fn clone(remote: Values<'_>) {
|
||||
|
||||
// create folder
|
||||
if first_iter {
|
||||
if DirBuilder::new().create(ref_path.clone()).is_err() {
|
||||
if let Ok(entries) = read_folder(ref_path.clone()) {
|
||||
if entries.len() != 0 {
|
||||
eprintln!("fatal: destination path '{}' already exists and is not an empty directory.", ref_path.display());
|
||||
if DirBuilder::new().recursive(true).create(ref_path.clone()).is_err() {
|
||||
eprintln!("fatal: unable to create the destination directory");
|
||||
std::process::exit(1);
|
||||
} else {
|
||||
init::init();
|
||||
}
|
||||
} else {
|
||||
eprintln!("fatal: cannot open the destination directory");
|
||||
std::process::exit(1);
|
||||
}
|
||||
} else {
|
||||
init::init();
|
||||
}
|
||||
} else {
|
||||
// create folder
|
||||
let p = ref_path.clone().join(Path::new(&relative_s));
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::env;
|
||||
use std::fs::{DirBuilder, File};
|
||||
use std::path::PathBuf;
|
||||
use crate::utils::read::read_folder;
|
||||
use crate::global::global::DIR_PATH;
|
||||
|
||||
pub fn init() {
|
||||
@ -10,6 +11,17 @@ pub fn init() {
|
||||
Some(dir) => PathBuf::from(dir),
|
||||
None => env::current_dir().unwrap(),
|
||||
};
|
||||
|
||||
if let Ok(entries) = read_folder(path.clone()) {
|
||||
if entries.len() != 0 {
|
||||
eprintln!("fatal: destination path '{}' already exists and is not an empty directory.", path.display());
|
||||
std::process::exit(1);
|
||||
}
|
||||
} else {
|
||||
eprintln!("fatal: cannot open the destination directory");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let builder = DirBuilder::new();
|
||||
// todo check if dir empty
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user