use std::path::PathBuf;
use super::Pipe;
use super::{Error, Result};
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Action {
path: PathBuf,
clean: Option<bool>,
}
impl Action {
pub async fn execute(&self, pipe: &mut Pipe) -> Result<()> {
super::validate_contained_path(&self.path, "output path")?;
let input = pipe.input().ok_or(Error::NoInputInPipe)?;
if self.path.exists() && self.clean.unwrap_or(true) {
tokio::fs::remove_dir_all(&self.path).await.map_err(|e| {
Error::CouldNotDeleteDirectory {
path: self.path.clone(),
err: e,
}
})?;
}
crate::util::fs::copy_dir(input.clone(), self.path.clone()).await
}
}