Skip to content
Merged
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
48 changes: 17 additions & 31 deletions crates/test-programs/src/bin/p1_path_open_preopen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,23 @@ unsafe fn path_open_preopen() {
)
.expect("open with O_DIRECTORY and read right");

if !test_programs::preview1::config().errno_expect_windows() {
// Open OFLAGS_DIRECTORY and read/write rights should fail with isdir:
let err = wasip1::path_open(
FIRST_PREOPEN,
0,
".",
wasip1::OFLAGS_DIRECTORY,
wasip1::RIGHTS_FD_READ | wasip1::RIGHTS_FD_WRITE,
0,
0,
)
.err()
.expect("open with O_DIRECTORY and read/write should fail");
assert_eq!(
err,
wasip1::ERRNO_ISDIR,
"opening directory read/write should fail with ISDIR"
);
} else {
// Open OFLAGS_DIRECTORY and read/write rights will succeed, only on windows:
let _ = wasip1::path_open(
FIRST_PREOPEN,
0,
".",
wasip1::OFLAGS_DIRECTORY,
wasip1::RIGHTS_FD_READ | wasip1::RIGHTS_FD_WRITE,
0,
0,
)
.expect("open with O_DIRECTORY and read/write should succeed on windows");
}
// Open OFLAGS_DIRECTORY and read/write rights should fail with isdir:
let err = wasip1::path_open(
FIRST_PREOPEN,
0,
".",
wasip1::OFLAGS_DIRECTORY,
wasip1::RIGHTS_FD_READ | wasip1::RIGHTS_FD_WRITE,
0,
0,
)
.err()
.expect("open with O_DIRECTORY and read/write should fail");
assert_eq!(
err,
wasip1::ERRNO_ISDIR,
"opening directory read/write should fail with ISDIR"
);
}

fn main() {
Expand Down
7 changes: 7 additions & 0 deletions crates/wasi-common/src/snapshots/preview_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,13 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
drop(dir_entry);

let fd = match file {
// Paper over a divergence between Windows and POSIX, where
// POSIX returns EISDIR if you open a directory with the
// WRITE flag: https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html#:~:text=EISDIR
#[cfg(windows)]
OpenResult::Dir(_) if write => {
return Err(types::Errno::Isdir.into());
}
OpenResult::File(file) => table.push(Arc::new(FileEntry::new(file, access_mode)))?,
OpenResult::Dir(child_dir) => table.push(Arc::new(DirEntry::new(None, child_dir)))?,
};
Expand Down
8 changes: 8 additions & 0 deletions crates/wasi/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,14 @@ impl Dir {
.await?;

match opened {
// Paper over a divergence between Windows and POSIX, where
// POSIX returns EISDIR if you open a directory with the
// WRITE flag: https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html#:~:text=EISDIR
#[cfg(windows)]
OpenResult::Dir(_) if flags.contains(DescriptorFlags::WRITE) => {
Err(ErrorCode::IsDirectory)
}

OpenResult::Dir(dir) => Ok(Descriptor::Dir(Dir::new(
dir,
self.perms,
Expand Down
2 changes: 0 additions & 2 deletions tests/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ const KNOWN_FAILURES: &[&str] = &[
#[cfg(windows)]
"path_open_missing",
#[cfg(windows)]
"path_open_preopen",
#[cfg(windows)]
"path_open_read_write",
#[cfg(windows)]
"path_rename",
Expand Down
Loading