wasmer_wasix/journal/effector/syscalls/
path_create_directory.rs

1use std::path::Path;
2
3use virtual_fs::FileSystem;
4
5use crate::VIRTUAL_ROOT_FD;
6
7use super::*;
8
9impl JournalEffector {
10    pub fn save_path_create_directory(
11        ctx: &mut FunctionEnvMut<'_, WasiEnv>,
12        fd: Fd,
13        path: String,
14    ) -> anyhow::Result<()> {
15        Self::save_event(
16            ctx,
17            JournalEntry::CreateDirectoryV1 {
18                fd,
19                path: path.into(),
20            },
21        )
22    }
23
24    pub fn apply_path_create_directory(
25        ctx: &mut FunctionEnvMut<'_, WasiEnv>,
26        fd: Fd,
27        path: &str,
28    ) -> anyhow::Result<()> {
29        // see `VIRTUAL_ROOT_FD` for details as to why this exists
30        if fd == VIRTUAL_ROOT_FD {
31            ctx.data().state.fs.root_fs.create_dir(Path::new(path))?;
32        } else {
33            crate::syscalls::path_create_directory_internal(ctx, fd, path).map_err(|err| {
34                anyhow::format_err!(
35                    "journal restore error: failed to create directory path (fd={fd}, path={path}) - {err}")
36            })?;
37        }
38        Ok(())
39    }
40}