Skip to content

wasi: path_open should accept a dir with RIGHT_FD_WRITE #2244

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

Merged
merged 3 commits into from
Jun 11, 2024
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
1 change: 0 additions & 1 deletion imports/wasi_snapshot_preview1/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,6 @@ func openFlags(dirflags, oflags, fdflags uint16, rights uint32) (openFlags exper
}
if oflags&wasip1.O_DIRECTORY != 0 {
openFlags |= experimentalsys.O_DIRECTORY
return // Early return for directories as the rest of flags doesn't make sense for it.
} else if oflags&wasip1.O_EXCL != 0 {
openFlags |= experimentalsys.O_EXCL
}
Expand Down
24 changes: 24 additions & 0 deletions imports/wasi_snapshot_preview1/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3937,6 +3937,30 @@ func Test_pathOpen(t *testing.T) {
expectedLog: `
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=file,oflags=,fs_rights_base=FD_READ|FD_WRITE,fs_rights_inheriting=,fdflags=)
<== (opened_fd=4,errno=ESUCCESS)
`,
},
{
name: "sysfs.DirFS file O_DIRECTORY RIGHTS_FD_WRITE",
fs: writeFS,
path: func(*testing.T) string { return fileName },
oflags: wasip1.O_DIRECTORY,
rights: wasip1.RIGHT_FD_WRITE,
expectedErrno: wasip1.ErrnoNotdir,
expectedLog: `
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=file,oflags=DIRECTORY,fs_rights_base=FD_WRITE,fs_rights_inheriting=,fdflags=)
<== (opened_fd=,errno=ENOTDIR)
`,
},
{
name: "sysfs.DirFS dir O_DIRECTORY RIGHTS_FD_WRITE",
fs: writeFS,
path: func(*testing.T) string { return dirName },
oflags: wasip1.O_DIRECTORY,
rights: wasip1.RIGHT_FD_WRITE,
expectedErrno: wasip1.ErrnoIsdir,
expectedLog: `
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=dir,oflags=DIRECTORY,fs_rights_base=FD_WRITE,fs_rights_inheriting=,fdflags=)
<== (opened_fd=,errno=EISDIR)
`,
},
}
Expand Down
3 changes: 0 additions & 3 deletions internal/sysfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func NewStdioFile(stdin bool, f fs.File) (fsapi.File, error) {
}

func OpenFile(path string, flag experimentalsys.Oflag, perm fs.FileMode) (*os.File, experimentalsys.Errno) {
if flag&experimentalsys.O_DIRECTORY != 0 && flag&(experimentalsys.O_WRONLY|experimentalsys.O_RDWR) != 0 {
return nil, experimentalsys.EISDIR // invalid to open a directory writeable
}
return openFile(path, flag, perm)
}

Expand Down
Loading