-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.fs.test file operations on directories
fails with Wasmtime 23.0.1
#20747
Comments
Just to clarify, what's the host system? Context: #13157 |
❯ uname -srm
Linux 6.5.0-44-generic x86_64 |
This could very easily be a bug in
|
This is actually pretty likely to be a bug in
EDIT: I'm not so certain that this is the same bug, I was doing something dumb while testing. |
Seems to be related to Without linking libc, the tests pass:
When linking libc, that test fails:
EDIT: The first
|
The plot thickens... The following test cases are built/run with
// This fails:
test "file operations on directories in tmpDir" {
var tmp_dir = testing.tmpDir(.{});
defer tmp_dir.cleanup();
const test_dir_name = "testdir";
try tmp_dir.dir.makeDir(test_dir_name);
try testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .mode = .read_write }));
}
// But this passes:
test "file operations on directories in cwd" {
const test_dir_name = "testdir";
try std.fs.cwd().deleteTree(test_dir_name);
try std.fs.cwd().makeDir(test_dir_name);
try testing.expectError(error.IsDir, std.fs.cwd().openFile(test_dir_name, .{ .mode = .read_write }));
} So somehow the usage of |
Found a reproduction with #include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
mkdirat(AT_FDCWD, "testdir", 0777);
{
// Opening with O_RDWR fails as expected if the dir fd is AT_FDCWD
int dir = openat(AT_FDCWD, "testdir", O_RDWR);
if (dir != -1) return 1;
}
// Open "testdir" for real now since we want to use it as the fd for openat
int dir = openat(AT_FDCWD, "testdir", O_RDONLY|O_DIRECTORY);
mkdirat(dir, "subdir", 0777);
// Try to open the subdir with O_RDWR, this should fail but it succeeds
// because the O_RDWR is lost and the openat2 syscall is called with O_RDONLY
// instead
int testdir = openat(dir, "subdir", O_RDWR);
if (testdir != -1) return 1;
return 0;
} $ WASI_SDK=/home/ryan/Downloads/wasi-sdk-23.0-x86_64-linux
$ $WASI_SDK/bin/clang --sysroot=$WASI_SDK/share/wasi-sysroot open-dir-tmpdir-rw.c -o open-dir-tmpdir-rw-sdk-23.wasm
$ strace -e trace=openat2 wasmtime --dir=. open-dir-tmpdir-rw-sdk-23.wasm
openat2(3, "testdir", {flags=O_RDWR|O_LARGEFILE|O_CLOEXEC, resolve=RESOLVE_NO_MAGICLINKS|RESOLVE_BENEATH}, 24) = -1 EISDIR (Is a directory)
openat2(3, "testdir", {flags=O_RDONLY|O_LARGEFILE|O_CLOEXEC, resolve=RESOLVE_NO_MAGICLINKS|RESOLVE_BENEATH}, 24) = 11
openat2(11, "subdir", {flags=O_RDONLY|O_LARGEFILE|O_CLOEXEC, resolve=RESOLVE_NO_MAGICLINKS|RESOLVE_BENEATH}, 24) = 12
+++ exited with 1 +++ The EDIT: Created a |
Zig Version
1fc42ed
Steps to Reproduce and Observed Behavior
-fwasmtime
(but seestd.Build.Step.Run
: Fix invocation syntax for Wasmtime 14+. #20745).Fails here:
zig/lib/std/fs/test.zig
Lines 767 to 769 in eac7fd4
Expected Behavior
No failure.
The text was updated successfully, but these errors were encountered: