Skip to content

Commit

Permalink
wasi: path_open should accept a dir with RIGHT_FD_WRITE (#2244)
Browse files Browse the repository at this point in the history
Signed-off-by: Yage Hu <me@huyage.dev>
  • Loading branch information
yagehu authored Jun 11, 2024
1 parent 0fa14a6 commit 8b3af37
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
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

0 comments on commit 8b3af37

Please sign in to comment.