From cdcc191c0b934cc611e7658edcac3398788028d2 Mon Sep 17 00:00:00 2001 From: Dean Li Date: Sat, 13 Mar 2021 14:47:29 +0800 Subject: [PATCH] Use `cfg_if!` for trait FilePath --- vm/src/stdlib/os.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 6967913a5..644075436 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -165,18 +165,20 @@ fn make_path(vm: &VirtualMachine, path: &PyPathLike, dir_fd: &DirFd) -> PyResult return Ok(path.into_os_string()); } - if cfg!(target_os = "wasi") { - return Err(vm.new_os_error("dir_fd not supported on wasi yet".to_owned())); - } - - let dir_path = match rust_file(dir_fd.0.unwrap().into()).path() { - Ok(dir_path) => dir_path, - Err(_) => { - return Err(vm.new_os_error(format!("Cannot determine path of dir_fd: {:?}", dir_fd.0))); + cfg_if::cfg_if! { + if #[cfg(target_os = "wasi")] { + return Err(vm.new_os_error("dir_fd not supported on wasi yet".to_owned())); + } else { + let dir_path = match rust_file(dir_fd.0.unwrap().into()).path() { + Ok(dir_path) => dir_path, + Err(_) => { + return Err(vm.new_os_error(format!("Cannot determine path of dir_fd: {:?}", dir_fd.0))); + } + }; + let p: PathBuf = vec![dir_path, path].iter().collect(); + Ok(p.into_os_string()) } - }; - let p: PathBuf = vec![dir_path, path].iter().collect(); - Ok(p.into_os_string()) + } } impl IntoPyException for io::Error {