about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2022-07-11 18:23:34 -0700
committerJosh Triplett <josh@joshtriplett.org>2022-07-15 02:54:06 -0700
commit3da17293e78198575c8adbab40ec783f250e9fe3 (patch)
tree26997a06e8b32fe43758042d94ce2e7711fd963c /library/std/src
parente387cff7a3eb442aa0a0b84a3ebb6f170e205ea2 (diff)
downloadrust-3da17293e78198575c8adbab40ec783f250e9fe3.tar.gz
rust-3da17293e78198575c8adbab40ec783f250e9fe3.zip
Don't fall back to futimes on Android; it needs a newer API level than futimens
Just return `io::ErrorKind::Unsupported` instead.
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/unix/fs.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
index 91deff71e42..59f17a8659d 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -1066,17 +1066,28 @@ impl File {
         cfg_if::cfg_if! {
             // futimens requires macOS 10.13, and Android API level 19
             if #[cfg(any(target_os = "android", target_os = "macos"))] {
-                fn ts_to_tv(ts: &libc::timespec) -> libc::timeval {
-                    libc::timeval { tv_sec: ts.tv_sec, tv_usec: (ts.tv_nsec / 1000) as _ }
-                }
                 cvt(unsafe {
                     weak!(fn futimens(c_int, *const libc::timespec) -> c_int);
-                    futimens.get()
-                        .map(|futimens| futimens(self.as_raw_fd(), times.0.as_ptr()))
-                        .unwrap_or_else(|| {
+                    match futimens.get() {
+                        Some(futimens) => futimens(self.as_raw_fd(), times.0.as_ptr()),
+                        #[cfg(target_os = "macos")]
+                        None => {
+                            fn ts_to_tv(ts: &libc::timespec) -> libc::timeval {
+                                libc::timeval {
+                                    tv_sec: ts.tv_sec,
+                                    tv_usec: (ts.tv_nsec / 1000) as _
+                                }
+                            }
                             let timevals = [ts_to_tv(&times.0[0]), ts_to_tv(&times.0[1])];
                             libc::futimes(self.as_raw_fd(), timevals.as_ptr())
-                        })
+                        }
+                        // futimes requires even newer Android.
+                        #[cfg(target_os = "android")]
+                        None => return Err(io::const_io_error!(
+                            io::ErrorKind::Unsupported,
+                            "setting file times requires Android API level >= 19",
+                        )),
+                    }
                 })?;
             } else {
                 cvt(unsafe { libc::futimens(self.as_raw_fd(), times.0.as_ptr()) })?;