Skip to content

Commit

Permalink
Merge #1660
Browse files Browse the repository at this point in the history
1660: Allow mapdir aliases with starting `/` r=MarkMcCaskey a=MarkMcCaskey

Stripping leading `/` is valid because we mount mapped dirs at `/` regardless.

Resolves #1503 

This solution is a bit hacky, there may be a more elegant solution.  I'll look for one tomorrow morning when I'm more mentally fresh.

- [ ] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Mark McCaskey <mark@wasmer.io>
  • Loading branch information
bors[bot] and Mark McCaskey authored Oct 1, 2020
2 parents d924639 + 9c208a1 commit cebf0cd
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 0 deletions.
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")
)

0 comments on commit cebf0cd

Please sign in to comment.