check if directory where the init command is clone is empty
This commit is contained in:
parent
39d1032c14
commit
d3592a5209
@ -80,18 +80,9 @@ 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().recursive(true).create(ref_path.clone()).is_err() {
|
||||||
if let Ok(entries) = read_folder(ref_path.clone()) {
|
eprintln!("fatal: unable to create the destination 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();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{DirBuilder, File};
|
use std::fs::{DirBuilder, File};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use crate::utils::read::read_folder;
|
||||||
use crate::global::global::DIR_PATH;
|
use crate::global::global::DIR_PATH;
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
@ -10,6 +11,17 @@ pub fn init() {
|
|||||||
Some(dir) => PathBuf::from(dir),
|
Some(dir) => PathBuf::from(dir),
|
||||||
None => env::current_dir().unwrap(),
|
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();
|
let builder = DirBuilder::new();
|
||||||
// todo check if dir empty
|
// todo check if dir empty
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user