use anyhow::{anyhow, Result};
use crate::context::DADKExecContext;
pub(super) fn delete(ctx: &DADKExecContext) -> Result<()> {
let sysroot_dir = ctx.sysroot_dir()?;
if !sysroot_dir.exists() {
return Err(anyhow!("Sysroot directory does not exist"));
}
if !sysroot_dir.is_dir() {
return Err(anyhow!("Sysroot path is not a directory"));
}
if !sysroot_dir.starts_with(&ctx.workdir()) {
return Err(anyhow!(
"Sysroot directory must be a subdirectory of the current working directory"
));
}
std::fs::remove_dir_all(sysroot_dir)?;
Ok(())
}