mirror of
https://github.com/termux/termux-packages.git
synced 2025-03-03 05:38:11 +00:00
59 lines
1.4 KiB
Diff
59 lines
1.4 KiB
Diff
--- a/src/unix/utimes.rs
|
|
+++ b/src/unix/utimes.rs
|
|
@@ -20,7 +20,7 @@
|
|
set_times(p, Some(atime), None, false)
|
|
}
|
|
|
|
-#[cfg(not(target_env = "uclibc"))]
|
|
+#[cfg(not(any(target_env = "uclibc", target_os = "android")))]
|
|
#[allow(dead_code)]
|
|
pub fn set_file_handle_times(
|
|
f: &fs::File,
|
|
@@ -40,7 +40,7 @@
|
|
};
|
|
}
|
|
|
|
-#[cfg(target_env = "uclibc")]
|
|
+#[cfg(any(target_env = "uclibc", target_os = "android"))]
|
|
#[allow(dead_code)]
|
|
pub fn set_file_handle_times(
|
|
f: &fs::File,
|
|
@@ -85,6 +85,7 @@
|
|
set_times(p, Some(atime), Some(mtime), true)
|
|
}
|
|
|
|
+#[cfg(not(target_os = "android"))]
|
|
pub fn set_times(
|
|
p: &Path,
|
|
atime: Option<FileTime>,
|
|
@@ -111,6 +112,29 @@
|
|
};
|
|
}
|
|
|
|
+#[cfg(target_os = "android")]
|
|
+pub fn set_times(
|
|
+ p: &Path,
|
|
+ atime: Option<FileTime>,
|
|
+ mtime: Option<FileTime>,
|
|
+ symlink: bool,
|
|
+) -> io::Result<()> {
|
|
+ let flags = if symlink {
|
|
+ libc::AT_SYMLINK_NOFOLLOW
|
|
+ } else {
|
|
+ 0
|
|
+ };
|
|
+
|
|
+ let p = CString::new(p.as_os_str().as_bytes())?;
|
|
+ let times = [super::to_timespec(&atime), super::to_timespec(&mtime)];
|
|
+ let rc = unsafe { libc::utimensat(libc::AT_FDCWD, p.as_ptr(), times.as_ptr(), flags) };
|
|
+ if rc == 0 {
|
|
+ Ok(())
|
|
+ } else {
|
|
+ Err(io::Error::last_os_error())
|
|
+ }
|
|
+}
|
|
+
|
|
fn to_timeval(ft: &FileTime) -> libc::timeval {
|
|
libc::timeval {
|
|
tv_sec: ft.seconds() as libc::time_t,
|