summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-11-27 16:28:47 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-11-27 16:28:47 +0000
commit1d2dace2040c856cb89cab3553ab70807e8ad364 (patch)
tree6f3eedcacef71137e1cbadaf704b50f7a5902a82 /src/sys
parent6920394524a558381e49a66a8dc11fe997fcce6c (diff)
parent12f10c76a5221d4977aca0646d615ae170d8722e (diff)
downloadnix-1d2dace2040c856cb89cab3553ab70807e8ad364.zip
Merge #967
967: Add a wrapper for lutimes(2) r=asomers a=jmmv PR #944 added wrappers for the more-modern futimens(2) and utimesat(2), but unfortunately these APIs are not available on old-ish systems. In particular, macOS Sierra and below don't implement them, making the new APIs unusable. Whether we should care about such "old" systems is debatable, but the problem is that, at the moment, this is the only macOS version usable on Travis to test kexts and, thus, to test FUSE file systems. This should have been part of PR #946, which added a wrapper for utimes(2) following this same rationale, but missed lutimes(2) because I simply didn't notice it existed. Co-authored-by: Julio Merino <julio@meroh.net>
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/stat.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index a0b3aafc..925c0ede 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -199,6 +199,26 @@ pub fn utimes<P: ?Sized + NixPath>(path: &P, atime: &TimeVal, mtime: &TimeVal) -
Errno::result(res).map(|_| ())
}
+/// Change the access and modification times of a file without following symlinks.
+///
+/// `lutimes(path, times)` is identical to
+/// `utimensat(None, path, times, UtimensatFlags::NoFollowSymlink)`. The former
+/// is a deprecated API so prefer using the latter if the platforms you care
+/// about support it.
+///
+/// # References
+///
+/// [lutimes(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/lutimes.html).
+#[cfg(not(target_os = "android"))]
+pub fn lutimes<P: ?Sized + NixPath>(path: &P, atime: &TimeVal, mtime: &TimeVal) -> Result<()> {
+ let times: [libc::timeval; 2] = [*atime.as_ref(), *mtime.as_ref()];
+ let res = path.with_nix_path(|cstr| unsafe {
+ libc::lutimes(cstr.as_ptr(), &times[0])
+ })?;
+
+ Errno::result(res).map(|_| ())
+}
+
/// Change the access and modification times of the file specified by a file descriptor.
///
/// # References