bytecodealliance / bytecodealliance/wasmtime

Cannot remove directories when the argument has a trailing "/"

Open
#8,828 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

Currently this program on Linux:

```rust
fn main() {
std::fs::remove_dir_all("temp-dir").unwrap();

std::fs::create_dir("temp-dir").unwrap();
std::fs::remove_dir("temp-dir").unwrap(); // this line passes
std::fs::create_dir("temp-dir").unwrap();
std::fs::remove_dir("temp-dir/").unwrap(); // this line fails
}
```

will fail to execute in Wasmtime:

```
wasmtime run --dir . ./foo.wasm
thread 'main' panicked at foo.rs:7:38:
called `Result::unwrap()` on an `Err` value: Os { code: 28, kind: InvalidInput, message: "Invalid argument" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: failed to run main module `./foo.wasm`
```

This causes [this test](https://github.com/WebAssembly/wasi-testsuite/blob/917cd15c556e5e656089130752b1bd8455a7d176/tests/rust/src/bin/remove_directory_trailing_slashes.rs#L18) to fail in the wasi-testsuite.

cc @sunfishcode I think this has something to do with [this function](https://github.com/bytecodealliance/cap-std/blob/1dc17d327bdcd44a0f5ec53d9fc671285be55b34/cap-primitives/src/fs/via_parent/open_parent.rs#L30-L39) being used [here](https://github.com/bytecodealliance/cap-std/blob/1dc17d327bdcd44a0f5ec53d9fc671285be55b34/cap-primitives/src/fs/via_parent/remove_dir.rs#L11-L13), although this code looks more subtle than my current understanding. Do you know if this has come up before with cap-std and/or if this is appropriate to fix there?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.