ambient_ci/action_impl/
mkdir.rs1use std::path::{Path, PathBuf};
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6 action::{ActionError, Context},
7 action_impl::ActionImpl,
8};
9
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct Mkdir {
17 pathname: PathBuf,
18}
19
20impl Mkdir {
21 pub fn new(pathname: PathBuf) -> Self {
23 Self { pathname }
24 }
25
26 pub fn pathname(&self) -> &Path {
28 &self.pathname
29 }
30}
31
32impl ActionImpl for Mkdir {
33 fn execute(&self, _context: &mut Context) -> Result<(), ActionError> {
34 if !self.pathname.exists() {
35 std::fs::create_dir(&self.pathname)
36 .map_err(|e| MkdirError::Mkdir(self.pathname.clone(), e))?;
37 }
38 Ok(())
39 }
40}
41
42#[derive(Debug, thiserror::Error)]
44pub enum MkdirError {
45 #[error("failed to create directory {0}")]
47 Mkdir(PathBuf, #[source] std::io::Error),
48}
49
50impl From<MkdirError> for ActionError {
51 fn from(value: MkdirError) -> Self {
52 Self::Mkdir(value)
53 }
54}