Skip to content

Commit

Permalink
cli: Exit anchor clean without error when dirs don't exist (coral-x…
Browse files Browse the repository at this point in the history
  • Loading branch information
cavemanloverboy committed May 27, 2023
1 parent 23b90bf commit 0c8498d
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3051,23 +3051,31 @@ fn clean(cfg_override: &ConfigOverride) -> Result<()> {
let target_dir = cfg_parent.join("target");
let deploy_dir = target_dir.join("deploy");

for entry in fs::read_dir(target_dir)? {
let path = entry?.path();
if path.is_dir() && path != deploy_dir {
fs::remove_dir_all(&path)
.map_err(|e| anyhow!("Could not remove directory {}: {}", path.display(), e))?;
} else if path.is_file() {
fs::remove_file(&path)
.map_err(|e| anyhow!("Could not remove file {}: {}", path.display(), e))?;
if target_dir.exists() {
for entry in fs::read_dir(target_dir)? {
let path = entry?.path();
if path.is_dir() && path != deploy_dir {
fs::remove_dir_all(&path)
.map_err(|e| anyhow!("Could not remove directory {}: {}", path.display(), e))?;
} else if path.is_file() {
fs::remove_file(&path)
.map_err(|e| anyhow!("Could not remove file {}: {}", path.display(), e))?;
}
}
} else {
println!("skipping target directory: not found")
}

for file in fs::read_dir(deploy_dir)? {
let path = file?.path();
if path.extension() != Some(&OsString::from("json")) {
fs::remove_file(&path)
.map_err(|e| anyhow!("Could not remove file {}: {}", path.display(), e))?;
if deploy_dir.exists() {
for file in fs::read_dir(deploy_dir)? {
let path = file?.path();
if path.extension() != Some(&OsString::from("json")) {
fs::remove_file(&path)
.map_err(|e| anyhow!("Could not remove file {}: {}", path.display(), e))?;
}
}
} else {
println!("skipping deploy directory: not found")
}

Ok(())
Expand Down

0 comments on commit 0c8498d

Please sign in to comment.