diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 3183339bf..f312d55cf 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -123,7 +123,6 @@ openssl = { version = "0.10.32", features = ["vendored"], optional = true } openssl-sys = { version = "0.9", optional = true } openssl-probe = { version = "0.1", optional = true } which = "4.0" -filepath = "0.1.1" [target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies] num_cpus = "1" @@ -148,5 +147,8 @@ features = [ [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = "0.2" +[target.'cfg(any(target_os = "linux", target_os = "macos", windows))'.dependencies] +filepath = "0.1.1" + [build-dependencies] itertools = "0.9" diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 41bf2f0d3..6041e2c55 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -7,7 +7,7 @@ use std::time::{Duration, SystemTime}; use std::{env, fs}; use crossbeam_utils::atomic::AtomicCell; -#[cfg(not(target_os = "wasi"))] +#[cfg(any(target_os = "linux", target_os = "macos", windows))] use filepath::FilePath; use num_bigint::BigInt; @@ -165,14 +165,12 @@ fn make_path<'a>( dir_fd: &DirFd, ) -> PyResult> { let path = &path.path; - if dir_fd.0.is_none() | path.is_absolute() { - return Ok(std::borrow::Cow::Borrowed(path.as_os_str().into())); + if dir_fd.0.is_none() || path.is_absolute() { + return Ok(path.as_os_str().into()); } 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 { + if #[cfg(any(target_os = "linux", target_os = "macos", windows))] { let dir_path = match rust_file(dir_fd.0.unwrap().into()).path() { Ok(dir_path) => dir_path, Err(_) => { @@ -181,6 +179,8 @@ fn make_path<'a>( }; let p: PathBuf = vec![dir_path, path.to_path_buf()].iter().collect(); Ok(p.into_os_string().into()) + } else { + return Err(vm.new_os_error("dir_fd not supported on wasi yet".to_owned())); } } }