Skip to content
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

Add test for creating directories at cwd #5232

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/wasix/src/syscalls/wasi/path_create_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ pub fn path_create_directory<M: MemorySize>(
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));
Expand Down
24 changes: 24 additions & 0 deletions tests/wasix/create-dir-at-cwd/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>

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;
}
5 changes: 5 additions & 0 deletions tests/wasix/create-dir-at-cwd/run.sh
Original file line number Diff line number Diff line change
@@ -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
Loading