MCPcopy Create free account
hub / github.com/PLSysSec/wave / wasi_path_remove_directory

Function wasi_path_remove_directory

src/wrappers.rs:668–694  ·  view source on GitHub ↗
(
    ctx: &mut VmCtx,
    v_fd: u32,
    pathname: u32,
    path_len: u32,
)

Source from the content-addressed store, hash-verified

666#[ensures(ctx_safe(ctx))]
667#[ensures(trace_safe(trace, ctx))]
668pub fn wasi_path_remove_directory(
669 ctx: &mut VmCtx,
670 v_fd: u32,
671 pathname: u32,
672 path_len: u32,
673) -> RuntimeResult<()> {
674 // let fd = ctx.fdmap.fd_to_native(v_fd)?;
675 if v_fd != HOMEDIR_FD {
676 return Err(Enotcapable);
677 }
678 assert!(v_fd == HOMEDIR_FD);
679 let fd = ctx.homedir_host_fd;
680
681 // unlinkat operates on symlinks
682 let host_pathname = ctx.translate_path(pathname, path_len, false, fd);
683 unwrap_result!(host_pathname);
684
685 let res = trace_unlinkat(ctx, fd, host_pathname, libc::AT_REMOVEDIR);
686 // posix spec allows unlinkat to return EEXIST for a non-empty directory
687 // however, the wasi spec requires that ENOTEMPTY is returned
688 // see: https://man7.org/linux/man-pages/man2/rmdir.2.html
689 if let Err(Eexist) = res {
690 return Err(RuntimeError::Enotempty);
691 }
692 res?;
693 Ok(())
694}
695
696// https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#path_rename
697// modifies: none

Calls 2

trace_unlinkatFunction · 0.85
translate_pathMethod · 0.80

Tested by

no test coverage detected