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

Allow mapdir aliases with starting / #1660

Merged
merged 5 commits into from
Oct 2, 2020
Merged
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
3 changes: 3 additions & 0 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ impl PreopenDirBuilder {

/// Make this preopened directory appear to the WASI program as `alias`
pub fn alias(&mut self, alias: &str) -> &mut Self {
// We mount at preopened dirs at `/` by default and multiple `/` in a row
// are equal to a single `/`.
let alias = alias.trim_start_matches('/');
self.alias = Some(alias.to_string());

self
Expand Down
2 changes: 2 additions & 0 deletions tests/ignores.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ wasitests::snapshot1::file_metadata on windows
wasitests::snapshot1::fseek on windows
wasitests::snapshot1::path_link on windows
wasitests::snapshot1::path_symlink on windows
wasitests::snapshot1::mapdir_with_leading_slash on windows
wasitests::unstable::fd_pread on windows
wasitests::unstable::fd_read on windows
wasitests::unstable::file_metadata on windows
wasitests::unstable::fseek on windows
wasitests::unstable::path_link on windows
wasitests::unstable::path_symlink on windows
wasitests::unstable::mapdir_with_leading_slash on windows

# This test is meant to only run on Unix
wasitests::unstable::unix_open_special_files on windows
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/snapshot1/mapdir_with_leading_slash.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "mapdir_with_leading_slash.wasm"
(map_dirs "/hamlet:test_fs/hamlet")
(assert_return (i64.const 0))
(assert_stdout "File exists? true\nSCENE III. A room in the castle.\n\n Enter KING CLAUDIUS, ROSENCRANTZ, and GUILDENSTERN \n\nKING CLAUDIUS\n\n I like him not, nor stands it safe with us\n To let his madness range. Therefore prepare you;\n I your commission will forthwith dispatch,\n \n")
)
23 changes: 23 additions & 0 deletions tests/wasi-wast/wasi/tests/mapdir_with_leading_slash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// WASI:
// mapdir: /hamlet:test_fs/hamlet

use std::fs;
use std::io::Read;
use std::path::PathBuf;

fn main() {
#[cfg(not(target_os = "wasi"))]
let mut base = PathBuf::from("test_fs/hamlet");
#[cfg(target_os = "wasi")]
let mut base = PathBuf::from("hamlet");

base.push("act3/scene3.txt");

println!("File exists? {}", base.exists());

let mut f = fs::File::open(&base).unwrap();
let mut s = String::new();
f.read_to_string(&mut s).unwrap();

println!("{}", s.chars().take(256).collect::<String>());
}
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/unstable/mapdir_with_leading_slash.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "mapdir_with_leading_slash.wasm"
(map_dirs "/hamlet:test_fs/hamlet")
(assert_return (i64.const 0))
(assert_stdout "File exists? true\nSCENE III. A room in the castle.\n\n Enter KING CLAUDIUS, ROSENCRANTZ, and GUILDENSTERN \n\nKING CLAUDIUS\n\n I like him not, nor stands it safe with us\n To let his madness range. Therefore prepare you;\n I your commission will forthwith dispatch,\n \n")
)