crate::ix!();
#[async_trait]
impl<P,H:CrateHandleInterface<P>> CleanupWorkspace for Workspace<P,H>
where for<'async_trait> P: From<PathBuf> + AsRef<Path> + Send + Sync + 'async_trait
{
async fn cleanup_workspace(&self) -> Result<(), WorkspaceError> {
let dirs_to_clean = vec![self.as_ref().join("target")];
let files_to_clean = vec![self.as_ref().join("Cargo.lock")];
for dir in dirs_to_clean {
if fs::metadata(&dir).await.is_ok() {
fs::remove_dir_all(&dir).await.map_err(|_| WorkspaceError::DirectoryRemovalError)?;
}
}
for file in files_to_clean {
if fs::metadata(&file).await.is_ok() {
fs::remove_file(&file).await.map_err(|_| WorkspaceError::FileRemovalError)?;
}
}
Ok(())
}
}