Skip to content

Commit 3da1729

Browse files
committed
Don't fall back to futimes on Android; it needs a newer API level than futimens
Just return `io::ErrorKind::Unsupported` instead.
1 parent e387cff commit 3da1729

File tree

1 file changed

+18
-7
lines changed
  • library/std/src/sys/unix

1 file changed

+18
-7
lines changed

library/std/src/sys/unix/fs.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -1066,17 +1066,28 @@ impl File {
10661066
cfg_if::cfg_if! {
10671067
// futimens requires macOS 10.13, and Android API level 19
10681068
if #[cfg(any(target_os = "android", target_os = "macos"))] {
1069-
fn ts_to_tv(ts: &libc::timespec) -> libc::timeval {
1070-
libc::timeval { tv_sec: ts.tv_sec, tv_usec: (ts.tv_nsec / 1000) as _ }
1071-
}
10721069
cvt(unsafe {
10731070
weak!(fn futimens(c_int, *const libc::timespec) -> c_int);
1074-
futimens.get()
1075-
.map(|futimens| futimens(self.as_raw_fd(), times.0.as_ptr()))
1076-
.unwrap_or_else(|| {
1071+
match futimens.get() {
1072+
Some(futimens) => futimens(self.as_raw_fd(), times.0.as_ptr()),
1073+
#[cfg(target_os = "macos")]
1074+
None => {
1075+
fn ts_to_tv(ts: &libc::timespec) -> libc::timeval {
1076+
libc::timeval {
1077+
tv_sec: ts.tv_sec,
1078+
tv_usec: (ts.tv_nsec / 1000) as _
1079+
}
1080+
}
10771081
let timevals = [ts_to_tv(&times.0[0]), ts_to_tv(&times.0[1])];
10781082
libc::futimes(self.as_raw_fd(), timevals.as_ptr())
1079-
})
1083+
}
1084+
// futimes requires even newer Android.
1085+
#[cfg(target_os = "android")]
1086+
None => return Err(io::const_io_error!(
1087+
io::ErrorKind::Unsupported,
1088+
"setting file times requires Android API level >= 19",
1089+
)),
1090+
}
10801091
})?;
10811092
} else {
10821093
cvt(unsafe { libc::futimens(self.as_raw_fd(), times.0.as_ptr()) })?;

0 commit comments

Comments
 (0)