Skip to content

Commit

Permalink
wasi: swap the directory order for --mapdir to match wasmtime --dir
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Feb 28, 2024
1 parent 4d5691e commit 2cb28db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static const char *opt_metavars[] = {
#if defined(TOYWASM_ENABLE_WASI)
[opt_wasi_env] = "NAME=VAR",
[opt_wasi_dir] = "DIR",
[opt_wasi_mapdir] = "GUEST_DIR::HOST_DIR",
[opt_wasi_mapdir] = "HOST_DIR::GUEST_DIR",
#endif
#if defined(TOYWASM_ENABLE_WASI_LITTLEFS)
[opt_wasi_mapdir_littlefs] = "LITTLEFS_IMAGE_PATH::LFS_DIR::GUEST_DIR",
Expand Down
11 changes: 7 additions & 4 deletions libwasi/wasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,21 @@ wasi_instance_prestat_add_vfs(struct wasi_instance *wasi, const char *path,

if (is_mapdir) {
/*
* <wasm dir>::<host dir>
* <host dir>::<wasm dir>
*
* intended to be compatible with wasmtime's --mapdir
* intended to be compatible with wasmtime's --dir
*
* cf.
* https://github.com/bytecodealliance/wasmtime/pull/7301
*/

const char *colon = strchr(path, ':');
if (colon == NULL || colon[1] != ':') {
ret = EINVAL;
goto fail;
}
wasm_path = strndup(path, colon - path);
host_path = strdup(colon + 2);
host_path = strndup(path, colon - path);
wasm_path = strdup(colon + 2);
} else {
host_path = strdup(path);
}
Expand Down

0 comments on commit 2cb28db

Please sign in to comment.