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

Canonicalize the host path passed to --mapdir #4018

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions lib/cli-compiler/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Utility functions for the WebAssembly module
use anyhow::{bail, Result};
use std::env;
use anyhow::{bail, Context, Result};
use std::path::PathBuf;
use std::{env, path::Path};

/// Whether or not Wasmer should print with color
pub fn wasmer_should_print_color() -> bool {
Expand All @@ -12,14 +12,18 @@ pub fn wasmer_should_print_color() -> bool {
}

fn retrieve_alias_pathbuf(alias: &str, real_dir: &str) -> Result<(String, PathBuf)> {
let pb = PathBuf::from(&real_dir);
let pb = Path::new(real_dir)
.canonicalize()
.with_context(|| format!("Unable to get the absolute path for \"{real_dir}\""))?;

if let Ok(pb_metadata) = pb.metadata() {
if !pb_metadata.is_dir() {
bail!("\"{}\" exists, but it is not a directory", &real_dir);
bail!("\"{real_dir}\" exists, but it is not a directory");
}
} else {
bail!("Directory \"{}\" does not exist", &real_dir);
bail!("Directory \"{real_dir}\" does not exist");
}

Ok((alias.to_string(), pb))
}

Expand Down
3 changes: 3 additions & 0 deletions lib/wasix/src/runners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use crate::runtime::{
/// instance (the "guest").
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct MappedDirectory {
/// The absolute path for a directory on the host filesystem.
theduke marked this conversation as resolved.
Show resolved Hide resolved
pub host: std::path::PathBuf,
/// The absolute path specifying where the host directory should be mounted
/// inside the guest.
pub guest: String,
}

Expand Down
25 changes: 19 additions & 6 deletions tests/integration/cli/tests/run_unstable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//! Integration tests for `wasmer run2`.
//!
//! Note that you will need to manually compile the `wasmer` CLI in release mode
//! before running any of these tests.
use std::{
io::{ErrorKind, Read},
process::Stdio,
Expand Down Expand Up @@ -34,10 +30,10 @@ fn wasmer_run_unstable() -> std::process::Command {
cmd.arg("run")
.arg("--quiet")
.arg("--package=wasmer-cli")
.arg("--features=singlepass,cranelift")
.arg("--features=singlepass,cranelift,compiler")
.arg("--color=never")
.arg("--")
.arg("run-unstable");
.arg("run");
cmd.env("RUST_LOG", &*RUST_LOG);
cmd
}
Expand All @@ -61,6 +57,23 @@ mod webc_on_disk {
assert.success().stdout(contains("Hello, World!"));
}

/// See <https://github.com/wasmerio/wasmer/issues/4010> for more.
#[test]
fn wasi_runner_mount_using_relative_directory_on_the_host() {
let temp = TempDir::new_in(env!("CARGO_TARGET_TMPDIR")).unwrap();
std::fs::write(temp.path().join("main.py"), "print('Hello, World!')").unwrap();

let assert = wasmer_run_unstable()
.arg(fixtures::python())
.arg("--mapdir=/app:.")
.arg("--")
.arg("/app/main.py")
.current_dir(temp.path())
.assert();

assert.success().stdout(contains("Hello, World!"));
}

#[test]
#[cfg_attr(
all(target_env = "musl", target_os = "linux"),
Expand Down