Skip to content

Commit 8b3af37

Browse files
authored
wasi: path_open should accept a dir with RIGHT_FD_WRITE (#2244)
Signed-off-by: Yage Hu <me@huyage.dev>
1 parent 0fa14a6 commit 8b3af37

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

imports/wasi_snapshot_preview1/fs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,6 @@ func openFlags(dirflags, oflags, fdflags uint16, rights uint32) (openFlags exper
17081708
}
17091709
if oflags&wasip1.O_DIRECTORY != 0 {
17101710
openFlags |= experimentalsys.O_DIRECTORY
1711-
return // Early return for directories as the rest of flags doesn't make sense for it.
17121711
} else if oflags&wasip1.O_EXCL != 0 {
17131712
openFlags |= experimentalsys.O_EXCL
17141713
}

imports/wasi_snapshot_preview1/fs_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3937,6 +3937,30 @@ func Test_pathOpen(t *testing.T) {
39373937
expectedLog: `
39383938
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=file,oflags=,fs_rights_base=FD_READ|FD_WRITE,fs_rights_inheriting=,fdflags=)
39393939
<== (opened_fd=4,errno=ESUCCESS)
3940+
`,
3941+
},
3942+
{
3943+
name: "sysfs.DirFS file O_DIRECTORY RIGHTS_FD_WRITE",
3944+
fs: writeFS,
3945+
path: func(*testing.T) string { return fileName },
3946+
oflags: wasip1.O_DIRECTORY,
3947+
rights: wasip1.RIGHT_FD_WRITE,
3948+
expectedErrno: wasip1.ErrnoNotdir,
3949+
expectedLog: `
3950+
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=file,oflags=DIRECTORY,fs_rights_base=FD_WRITE,fs_rights_inheriting=,fdflags=)
3951+
<== (opened_fd=,errno=ENOTDIR)
3952+
`,
3953+
},
3954+
{
3955+
name: "sysfs.DirFS dir O_DIRECTORY RIGHTS_FD_WRITE",
3956+
fs: writeFS,
3957+
path: func(*testing.T) string { return dirName },
3958+
oflags: wasip1.O_DIRECTORY,
3959+
rights: wasip1.RIGHT_FD_WRITE,
3960+
expectedErrno: wasip1.ErrnoIsdir,
3961+
expectedLog: `
3962+
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=dir,oflags=DIRECTORY,fs_rights_base=FD_WRITE,fs_rights_inheriting=,fdflags=)
3963+
<== (opened_fd=,errno=EISDIR)
39403964
`,
39413965
},
39423966
}

internal/sysfs/file.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ func NewStdioFile(stdin bool, f fs.File) (fsapi.File, error) {
3838
}
3939

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

0 commit comments

Comments
 (0)