wasmer_wasix/journal/effector/syscalls/
path_remove_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_remove_directory(
11        ctx: &mut FunctionEnvMut<'_, WasiEnv>,
12        fd: Fd,
13        path: String,
14    ) -> anyhow::Result<()> {
15        Self::save_event(
16            ctx,
17            JournalEntry::RemoveDirectoryV1 {
18                fd,
19                path: Cow::Owned(path),
20            },
21        )
22    }
23
24    pub fn apply_path_remove_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.remove_dir(Path::new(path))?;
32        } else if let Err(err) = crate::syscalls::path_remove_directory_internal(ctx, fd, path) {
33            bail!("journal restore error: failed to remove directory - {err}");
34        }
35        Ok(())
36    }
37}