diff options
| author | Cody Tapscott <topolarity@tapscott.me> | 2022-03-03 12:25:21 -0700 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2022-04-16 18:08:05 +0200 |
| commit | 7b090df6689909ba82ff46be4d21733f84f32c33 (patch) | |
| tree | 105f0782e6ec8cd105402c689db814f8720c5858 /lib/std/os | |
| parent | 8f75823728d247bc11d916b7257d7eebc7be06de (diff) | |
| download | zig-7b090df6689909ba82ff46be4d21733f84f32c33.tar.gz zig-7b090df6689909ba82ff46be4d21733f84f32c33.zip | |
stdlib std.os: Improve wasi-libc parity for WASI CWD emulation
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.
Diffstat (limited to 'lib/std/os')
| -rw-r--r-- | lib/std/os/test.zig | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 8598c7b3be..ae0d14ef7e 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -49,7 +49,7 @@ test "chdir smoke test" { test "open smoke test" { if (native_os == .wasi and builtin.link_libc) return error.SkipZigTest; - if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "."); + if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "/"); // TODO verify file attributes using `fstat` @@ -104,7 +104,7 @@ test "open smoke test" { test "openat smoke test" { if (native_os == .wasi and builtin.link_libc) return error.SkipZigTest; - if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "."); + if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "/"); // TODO verify file attributes using `fstatat` @@ -141,7 +141,7 @@ test "openat smoke test" { test "symlink with relative paths" { if (native_os == .wasi and builtin.link_libc) return error.SkipZigTest; - if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "."); + if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "/"); const cwd = fs.cwd(); cwd.deleteFile("file.txt") catch {}; @@ -197,7 +197,7 @@ test "link with relative paths" { if (builtin.link_libc) { return error.SkipZigTest; } else { - try os.initPreopensWasi(std.heap.page_allocator, "."); + try os.initPreopensWasi(std.heap.page_allocator, "/"); } }, .linux, .solaris => {}, @@ -237,7 +237,7 @@ test "link with relative paths" { test "linkat with different directories" { switch (native_os) { - .wasi => if (!builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "."), + .wasi => if (!builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "/"), .linux, .solaris => {}, else => return error.SkipZigTest, } @@ -898,7 +898,7 @@ test "POSIX file locking with fcntl" { test "rename smoke test" { if (native_os == .wasi and builtin.link_libc) return error.SkipZigTest; - if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "."); + if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "/"); var tmp = tmpDir(.{}); defer tmp.cleanup(); @@ -955,7 +955,7 @@ test "rename smoke test" { test "access smoke test" { if (native_os == .wasi and builtin.link_libc) return error.SkipZigTest; - if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "."); + if (native_os == .wasi and !builtin.link_libc) try os.initPreopensWasi(std.heap.page_allocator, "/"); var tmp = tmpDir(.{}); defer tmp.cleanup(); |
