-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
stdlib std.os: Update CWD emulation to match wasi-libc behavior #11053
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
Conversation
cc @zigazeljko Can you take a peek at 4830e16 here and see what you think of the new approach? I'm open to any alternatives or concerns that might jump out to you. |
Looks good to me. |
4830e16
to
0fff5c4
Compare
#11021 is now merged - would you mind rebasing onto master please? |
a6b53cd
to
5d9f508
Compare
|
A very good question. This would be canonicalized as Whether this behavior is "right" probably depends on how WebAssembly/wasi-filesystem#24 is resolved. I don't have a strong argument either way, right now
The WASI implementation for
That seems like it should be tackled in your existing PR #10988 |
5d9f508
to
abd9e4b
Compare
Two major changes here: 1. We store the CWD as a simple `[]const u8` and lookup Preopens for every absolute or CWD-referenced file operation, based on the Preopen with the longest match (i.e. most specific path) 2. Preorders are normalized to POSIX absolute paths at init time. Behavior depends on the "cwd_root" parameter of `initPreopensWasi`: `cwd_root` is used for any Preopens that start with "." For example: "./foo/bar" - inits to -> "{cwd_root}/foo/bar" "foo/bar" - inits to -> "/foo/bar" "/foo/bar" - inits to -> "/foo/bar" `cwd_root` must be an absolute path. Using "/" as `cwd_root` gives behavior similar to wasi-libc.
abd9e4b
to
8f6fd5e
Compare
Dependent on #11021 .
Some more work is needed to align our CWD treatment on WASI with wasi-libc. This is particularly important for runtimes like wasmer, which inserts a special "/" Preopen by default and also strips leading slashes from other Preopens
Here's the idea behind these changes:
[]const u8
. We lookup Preopens for every absolute or CWD-referenced file operation, based on the Preopen with the longest match (i.e. most specific path)cwd_root
parameter ofinitPreopensWasi
. cwd_root is used only for any Preopens that start with "." so that:The intention is that:
cwd_root
gives behavior similar to wasi-libcThese changes come at a performance cost, since we no longer cache any matching Preopen for the CWD, but the implementation is also much simpler and the compatibility gain from matching wasi-libc's behavior seems worth it.
Another consequence is that we no longer support
fchdir
on WASI