sysroot.rs 770 B

1234567891011121314151617181920212223242526
  1. use anyhow::{anyhow, Result};
  2. use crate::context::DADKExecContext;
  3. pub(super) fn delete(ctx: &DADKExecContext) -> Result<()> {
  4. let sysroot_dir = ctx.sysroot_dir()?;
  5. // 检查 sysroot_dir 是否存在
  6. if !sysroot_dir.exists() {
  7. return Err(anyhow!("Sysroot directory does not exist"));
  8. }
  9. // 检查 sysroot_dir 是否是一个目录
  10. if !sysroot_dir.is_dir() {
  11. return Err(anyhow!("Sysroot path is not a directory"));
  12. }
  13. // 检查 sysroot_dir 是否是当前工作目录的子目录
  14. if !sysroot_dir.starts_with(&ctx.workdir()) {
  15. return Err(anyhow!(
  16. "Sysroot directory must be a subdirectory of the current working directory"
  17. ));
  18. }
  19. std::fs::remove_dir_all(sysroot_dir)?;
  20. Ok(())
  21. }