This commit is contained in:
Thomas Forgione 2020-11-04 12:45:31 +01:00
parent b4cf2a63d6
commit 9fefbb8c3a

View File

@ -96,6 +96,10 @@ pub fn parse_to_url(server: &str, owner: &str, repo: &str) -> String {
/// ///
/// If an error happens, it deletes the directory created. /// If an error happens, it deletes the directory created.
pub fn clone<P: AsRef<Path>>(url: &str, place: P) -> Result<()> { pub fn clone<P: AsRef<Path>>(url: &str, place: P) -> Result<()> {
if place.as_ref().exists() {
return Err(Error::PathAlreadyExists);
}
match clone_dirty(url, &place) { match clone_dirty(url, &place) {
Ok(o) => Ok(o), Ok(o) => Ok(o),
Err(e) => { Err(e) => {
@ -109,10 +113,6 @@ pub fn clone<P: AsRef<Path>>(url: &str, place: P) -> Result<()> {
fn clone_dirty<P: AsRef<Path>>(url: &str, place: P) -> Result<()> { fn clone_dirty<P: AsRef<Path>>(url: &str, place: P) -> Result<()> {
let place = place.as_ref(); let place = place.as_ref();
if place.exists() {
return Err(Error::PathAlreadyExists);
}
// Need to create the parent dir only if it exists // Need to create the parent dir only if it exists
if let Some(parent) = place.parent() { if let Some(parent) = place.parent() {
create_dir_all(parent)?; create_dir_all(parent)?;
@ -123,7 +123,7 @@ fn clone_dirty<P: AsRef<Path>>(url: &str, place: P) -> Result<()> {
"clone", "clone",
"--recurse-submodules", "--recurse-submodules",
&url, &url,
&place.display().to_string() &place.display().to_string(),
]) ])
.stderr(Stdio::null()) .stderr(Stdio::null())
.status(); .status();