From 2d2e6d16a13063241ea4e0087959516df4756223 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 11 Jan 2021 15:15:54 -0800 Subject: [PATCH] Dir::open_file, open_dir: correct symlink following --- crates/wasi-c2/src/dir.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/wasi-c2/src/dir.rs b/crates/wasi-c2/src/dir.rs index 04a8423d38..72971b0e68 100644 --- a/crates/wasi-c2/src/dir.rs +++ b/crates/wasi-c2/src/dir.rs @@ -263,6 +263,8 @@ impl WasiDir for cap_std::fs::Dir { if symlink_follow { opts.follow(FollowSymlinks::Yes); + } else { + opts.follow(FollowSymlinks::No); } let f = self.open_with(Path::new(path), &opts)?; @@ -270,8 +272,12 @@ impl WasiDir for cap_std::fs::Dir { } fn open_dir(&self, symlink_follow: bool, path: &str) -> Result, Error> { - // XXX obey symlink_follow - let d = self.open_dir(Path::new(path))?; + let d = if symlink_follow { + self.open_dir(Path::new(path))? + } else { + use cap_fs_ext::DirExt; + self.open_dir_nofollow(Path::new(path))? + }; Ok(Box::new(d)) }