tests: directory seeking is actually prohibited! but the test was wrong

* path_open of a directory without OFLAGS_DIRECTORY worked on linux,
  but fortunately not on windows!
* the errno is BADF instead of NOTCAPABLE for fd_seek on a directory
* no way for a directory to have the FD_SEEK right.
This commit is contained in:
Pat Hickey
2021-01-25 12:13:02 -08:00
parent 2b70ea8b91
commit 634e911a4b

View File

@@ -7,8 +7,16 @@ unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
wasi::path_create_directory(dir_fd, "dir").expect("failed to make directory"); wasi::path_create_directory(dir_fd, "dir").expect("failed to make directory");
// Open the directory and attempt to request rights for seeking. // Open the directory and attempt to request rights for seeking.
let fd = wasi::path_open(dir_fd, 0, "dir", 0, wasi::RIGHTS_FD_SEEK, 0, 0) let fd = wasi::path_open(
.expect("failed to open file"); dir_fd,
0,
"dir",
wasi::OFLAGS_DIRECTORY,
wasi::RIGHTS_FD_SEEK,
0,
0,
)
.expect("failed to open file");
assert_gt!( assert_gt!(
fd, fd,
libc::STDERR_FILENO as wasi::Fd, libc::STDERR_FILENO as wasi::Fd,
@@ -20,8 +28,8 @@ unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
wasi::fd_seek(fd, 0, wasi::WHENCE_CUR) wasi::fd_seek(fd, 0, wasi::WHENCE_CUR)
.expect_err("seek on a directory") .expect_err("seek on a directory")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTCAPABLE, wasi::ERRNO_BADF,
"errno should be ERRNO_NOTCAPABLE" "errno should be BADF"
); );
// Check if we obtained the right to seek. // Check if we obtained the right to seek.
@@ -33,8 +41,8 @@ unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
); );
assert_eq!( assert_eq!(
(fdstat.fs_rights_base & wasi::RIGHTS_FD_SEEK), (fdstat.fs_rights_base & wasi::RIGHTS_FD_SEEK),
wasi::RIGHTS_FD_SEEK, 0,
"directory has the seek right", "directory does NOT have the seek right",
); );
// Clean up. // Clean up.