Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dirs": ["fs-tests.dir"]
}
54 changes: 54 additions & 0 deletions tests/rust/wasm32-wasip3/src/bin/filesystem-unlink-errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::process;
extern crate wit_bindgen;

wit_bindgen::generate!({
inline: r"
package test:test;

world test {
include wasi:filesystem/[email protected];
include wasi:cli/[email protected];
}
",
additional_derives: [PartialEq, Eq, Hash, Clone],
// Work around https://github.com/bytecodealliance/wasm-tools/issues/2285.
features:["clocks-timezone"],
generate_all
});

use wasi::filesystem::types::Descriptor;
use wasi::filesystem::types::ErrorCode;

async fn test_unlink_errors(dir: &Descriptor) {
let rm = |path: &str| dir.unlink_file_at(path.to_string());
assert_eq!(rm("").await, Err(ErrorCode::NoEntry));
assert_eq!(rm(".").await, Err(ErrorCode::IsDirectory));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows Wasmtime error:
Test filesystem-unlink-errors failed
[exit_code] 0 == 3
STDOUT:

STDERR:

thread '' (1) panicked at src/bin/filesystem-unlink-errors.rs:25:5:
assertion left == right failed
left: Err(ErrorCode { code: 0, name: "access", message: "Permission denied, similar to EACCES in POSIX." })
right: Err(ErrorCode { code: 13, name: "is-directory", message: "Is a directory, similar to EISDIR in POSIX." })
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Error: failed to run main module tests\rust\testsuite\wasm32-wasip3\filesystem-unlink-errors.wasm

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MacOS error:
Test filesystem-unlink-errors failed
[exit_code] 0 == 134
STDOUT:

STDERR:

thread '' (1) panicked at src/bin/filesystem-unlink-errors.rs:25:5:
assertion left == right failed
left: Err(ErrorCode { code: 30, name: "not-permitted", message: "Operation not permitted, similar to EPERM in POSIX." })
right: Err(ErrorCode { code: 13, name: "is-directory", message: "Is a directory, similar to EISDIR in POSIX." })
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Error: failed to run main module tests/rust/testsuite/wasm32-wasip3/filesystem-unlink-errors.wasm

assert_eq!(rm("..").await, Err(ErrorCode::NotPermitted));
assert_eq!(rm("../fs-tests.dir").await, Err(ErrorCode::NotPermitted));
assert_eq!(rm("/").await, Err(ErrorCode::NotPermitted));
assert_eq!(rm("/etc/passwd").await, Err(ErrorCode::NotPermitted));
assert_eq!(rm("/etc/passwd").await, Err(ErrorCode::NotPermitted));
assert_eq!(rm("z.txt").await, Err(ErrorCode::NoEntry));
assert_eq!(rm("parent/z.txt").await, Err(ErrorCode::NotPermitted));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these errors follow POSIX, and I think that if Windows diverges, there should be some adapter code. WDYT @alexcrichton ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory that seems reasonable to me yeah. Given how tricky this can be though I wouldn't be confident in saying it's the best solution until there's an implementation. For example a simple "map this code to that code" is totally fine, but if it otherwise requires a lot of other contextual information or flags-on-files or something then that's less reasonable. I'm not sure which bucket this would fall into.

}

struct Component;
export!(Component);
impl exports::wasi::cli::run::Guest for Component {
async fn run() -> Result<(), ()> {
match &wasi::filesystem::preopens::get_directories()[..] {
[(dir, dirname)] if dirname == "fs-tests.dir" => {
test_unlink_errors(dir).await;
}
[..] => {
eprintln!("usage: run with one open dir named 'fs-tests.dir'");
process::exit(1)
}
};
Ok(())
}
}

fn main() {
unreachable!("main is a stub");
}
Loading