bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.21k stars 1.28k forks source link

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

Open alexcrichton opened 3 months ago

alexcrichton commented 3 months ago

Currently this program on Linux:

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 to fail in the wasi-testsuite.

cc @sunfishcode I think this has something to do with this function being used here, 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?