wasmer_wasix/journal/effector/syscalls/
path_unlink.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_unlink(
11        ctx: &mut FunctionEnvMut<'_, WasiEnv>,
12        fd: Fd,
13        path: String,
14    ) -> anyhow::Result<()> {
15        Self::save_event(
16            ctx,
17            JournalEntry::UnlinkFileV1 {
18                fd,
19                path: Cow::Owned(path),
20            },
21        )
22    }
23
24    pub fn apply_path_unlink(
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_file(Path::new(path))?;
32        } else {
33            let ret = crate::syscalls::path_unlink_file_internal(ctx, fd, path)?;
34            if ret != Errno::Success {
35                bail!(
36                    "journal restore error: failed to remove file (fd={fd}, path={path}) - {ret}"
37                );
38            }
39        }
40        Ok(())
41    }
42}