Skip to content

Commit

Permalink
deleting created directories if clone fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcd committed Apr 26, 2022
1 parent 11c4df2 commit 3a79722
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/action_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ pub fn clone(relative_path_string: String) {
let relative_path_components = relative_path.components().collect::<Vec<_>>();
let mut current_dir = std::env::current_dir().unwrap();

let mut created_directories: Vec<PathBuf> = vec![];

for relative_path_component in relative_path_components {
let create_dir = current_dir.join(relative_path_component);
if !create_dir.exists() {
debug!("creating directory '{}'", create_dir.to_str().unwrap());
std::fs::create_dir_all(&create_dir).unwrap();
created_directories.push(create_dir.clone());
}
current_dir = create_dir;
}
Expand Down Expand Up @@ -107,6 +110,16 @@ pub fn clone(relative_path_string: String) {
root_file.add_repository(absolute_repository_path.to_str().unwrap());
root_file.write();
}
else {
debug!("Cloning failed.");
debug!("Deleting created directories...");
for created_directory in created_directories {
if created_directory.exists() {
debug!("Deleting directory '{}'", created_directory.to_str().unwrap());
std::fs::remove_dir_all(&created_directory).unwrap();
}
}
}

println!("{}", message);
process::exit(status_code);
Expand Down

0 comments on commit 3a79722

Please sign in to comment.