diff --git a/lib/wasix/src/syscalls/wasi/path_create_directory.rs b/lib/wasix/src/syscalls/wasi/path_create_directory.rs index 60343269fc2..c81adfd5c91 100644 --- a/lib/wasix/src/syscalls/wasi/path_create_directory.rs +++ b/lib/wasix/src/syscalls/wasi/path_create_directory.rs @@ -29,12 +29,11 @@ pub fn path_create_directory( let mut path_string = unsafe { get_input_str_ok!(&memory, path, path_len) }; Span::current().record("path", path_string.as_str()); - // Convert relative paths into absolute paths - if path_string.starts_with("./") { - path_string = ctx.data().state.fs.relative_path_to_absolute(path_string); - trace!( - %path_string - ); + let path = PathBuf::from(&path_string); + + if path.is_relative() { + let cur_dir = PathBuf::from(ctx.data().state.fs.current_dir.lock().unwrap().deref()); + path_string = cur_dir.join(path).to_str().unwrap().to_owned(); } wasi_try_ok!(path_create_directory_internal(&mut ctx, fd, &path_string)); diff --git a/tests/wasix/create-dir-at-cwd/main.c b/tests/wasix/create-dir-at-cwd/main.c new file mode 100644 index 00000000000..5e36441ef2e --- /dev/null +++ b/tests/wasix/create-dir-at-cwd/main.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +int main() { + int status = EXIT_FAILURE; + + const char *dirName1 = "test1"; + if (mkdir(dirName1, 0755) != 0) { + goto end; + } + + const char *dirName2 = "./test2"; + if (mkdir(dirName2, 0755) != 0) { + goto end; + } + + status = EXIT_SUCCESS; + +end: + printf("%d", status); + return 0; +} diff --git a/tests/wasix/create-dir-at-cwd/run.sh b/tests/wasix/create-dir-at-cwd/run.sh new file mode 100755 index 00000000000..66be3793d6b --- /dev/null +++ b/tests/wasix/create-dir-at-cwd/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +$WASMER -q run main.wasm --dir . > output + +rmdir test1 test2 2>/dev/null && printf "0" | diff -u output - 1>/dev/null