Skip to content

Commit e469898

Browse files
committed
Add a cfg for os.stat for android
1 parent 9503449 commit e469898

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

vm/src/stdlib/os.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,25 @@ fn os_stat(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
359359
}
360360
}
361361

362+
#[cfg(target_os = "android")]
363+
fn os_stat(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
364+
use std::os::android::fs::MetadataExt;
365+
match fs::metadata(&path.value) {
366+
Ok(meta) => Ok(StatResult {
367+
st_mode: meta.st_mode(),
368+
st_ino: meta.st_ino(),
369+
st_dev: meta.st_dev(),
370+
st_nlink: meta.st_nlink(),
371+
st_uid: meta.st_uid(),
372+
st_gid: meta.st_gid(),
373+
st_size: meta.st_size(),
374+
}
375+
.into_ref(vm)
376+
.into_object()),
377+
Err(s) => Err(vm.new_os_error(s.to_string())),
378+
}
379+
}
380+
362381
#[cfg(windows)]
363382
fn os_stat(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
364383
use std::os::windows::fs::MetadataExt;
@@ -378,7 +397,12 @@ fn os_stat(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
378397
}
379398
}
380399

381-
#[cfg(all(not(target_os = "linux"), not(target_os = "macos"), not(windows)))]
400+
#[cfg(not(any(
401+
target_os = "linux",
402+
target_os = "macos",
403+
target_os = "android",
404+
windows
405+
)))]
382406
fn os_stat(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
383407
unimplemented!();
384408
}

0 commit comments

Comments
 (0)