bytecodealliance / preview2-prototyping

Polyfill adapter for preview1-using wasm modules to call preview2 functions.
Other
77 stars 20 forks source link

adapter: path_ apis return NOTDIR instead of BADF when passed file; fixes path_open_dirfd test. #152

Closed pchickey closed 1 year ago

pchickey commented 1 year ago

All preview1 path_ apis, as well as fd_readdir, now fail with NOTDIR if they are passed a file (non-directory) fd.

This behavior satisfies the path_open_dirfd test, but that only specifies the behavior of path_open when passed a non-dir.

This behavior comes from way back in https://github.com/CraneStation/wasi-misc-tests/pull/41 which expected NOTDIR to be the error for all *at-style functions.

sunfishcode commented 1 year ago

Looking at POSIX, all the *at functions fail with ENOTDIR when the dirfd is not a dir. Would it make sense to add a get_base_dir accessor to Descriptor which fails with ENOTDIR and then use that in all the *at functions?

pchickey commented 1 year ago

I believe the *at functions from linux are the path_* functions in WASI. Yes, we could switch them to return NOTDIR for files and BADF when the table entry is neither a dir nor a file. I believe this will require updating the test suite to expect that error in a bunch of other spots, though.

pchickey commented 1 year ago

@sunfishcode updated, with a test that shows every relevant failure gives NOTDIR

sunfishcode commented 1 year ago

Looks good!