From 7e097b4f4f80311cf9918275bf5a17fb3930ab56 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 30 Sep 2020 17:47:24 -0700 Subject: [PATCH] Clean up code and add comment --- lib/wasi/src/state/builder.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/wasi/src/state/builder.rs b/lib/wasi/src/state/builder.rs index b3636eecbbb..56fd0cea184 100644 --- a/lib/wasi/src/state/builder.rs +++ b/lib/wasi/src/state/builder.rs @@ -438,16 +438,9 @@ impl PreopenDirBuilder { /// Make this preopened directory appear to the WASI program as `alias` pub fn alias(&mut self, alias: &str) -> &mut Self { - let alias = if let Some(first_byte) = alias.as_bytes().first() { - if *first_byte == b'/' { - &alias[1..] - } else { - alias - } - } else { - alias - } - .to_string(); + // We mount at preopened dirs at `/` by default and multiple `/` in a row + // are equal to a single `/`. + let alias = alias.trim_start_matches(b'/'); self.alias = Some(alias); self