Skip to content

Commit cdcc191

Browse files
committed
Use cfg_if! for trait FilePath
1 parent 9e6a7ae commit cdcc191

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

vm/src/stdlib/os.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,20 @@ fn make_path(vm: &VirtualMachine, path: &PyPathLike, dir_fd: &DirFd) -> PyResult
165165
return Ok(path.into_os_string());
166166
}
167167

168-
if cfg!(target_os = "wasi") {
169-
return Err(vm.new_os_error("dir_fd not supported on wasi yet".to_owned()));
170-
}
171-
172-
let dir_path = match rust_file(dir_fd.0.unwrap().into()).path() {
173-
Ok(dir_path) => dir_path,
174-
Err(_) => {
175-
return Err(vm.new_os_error(format!("Cannot determine path of dir_fd: {:?}", dir_fd.0)));
168+
cfg_if::cfg_if! {
169+
if #[cfg(target_os = "wasi")] {
170+
return Err(vm.new_os_error("dir_fd not supported on wasi yet".to_owned()));
171+
} else {
172+
let dir_path = match rust_file(dir_fd.0.unwrap().into()).path() {
173+
Ok(dir_path) => dir_path,
174+
Err(_) => {
175+
return Err(vm.new_os_error(format!("Cannot determine path of dir_fd: {:?}", dir_fd.0)));
176+
}
177+
};
178+
let p: PathBuf = vec![dir_path, path].iter().collect();
179+
Ok(p.into_os_string())
176180
}
177-
};
178-
let p: PathBuf = vec![dir_path, path].iter().collect();
179-
Ok(p.into_os_string())
181+
}
180182
}
181183

182184
impl IntoPyException for io::Error {

0 commit comments

Comments
 (0)