diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-27 16:28:47 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-27 16:28:47 +0000 |
commit | 1d2dace2040c856cb89cab3553ab70807e8ad364 (patch) | |
tree | 6f3eedcacef71137e1cbadaf704b50f7a5902a82 /test | |
parent | 6920394524a558381e49a66a8dc11fe997fcce6c (diff) | |
parent | 12f10c76a5221d4977aca0646d615ae170d8722e (diff) | |
download | nix-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 'test')
-rw-r--r-- | test/test_stat.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/test/test_stat.rs b/test/test_stat.rs index 01d86a79..bd16e635 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -6,7 +6,7 @@ use std::time::{Duration, UNIX_EPOCH}; use libc::{S_IFMT, S_IFLNK}; use nix::fcntl; -use nix::sys::stat::{self, fchmod, fchmodat, fstat, futimens, lstat, stat, utimes, utimensat}; +use nix::sys::stat::{self, fchmod, fchmodat, fstat, futimens, lstat, lutimes, stat, utimes, utimensat}; use nix::sys::stat::{FileStat, Mode, FchmodatFlags, UtimensatFlags}; use nix::sys::time::{TimeSpec, TimeVal, TimeValLike}; use nix::unistd::chdir; @@ -179,6 +179,25 @@ fn test_utimes() { } #[test] +fn test_lutimes() { + let tempdir = tempfile::tempdir().unwrap(); + let target = tempdir.path().join("target"); + let fullpath = tempdir.path().join("symlink"); + drop(File::create(&target).unwrap()); + symlink(&target, &fullpath).unwrap(); + + let exp_target_metadata = fs::symlink_metadata(&target).unwrap(); + lutimes(&fullpath, &TimeVal::seconds(4560), &TimeVal::seconds(1230)).unwrap(); + assert_times_eq(4560, 1230, &fs::symlink_metadata(&fullpath).unwrap()); + + let target_metadata = fs::symlink_metadata(&target).unwrap(); + assert_eq!(exp_target_metadata.accessed().unwrap(), target_metadata.accessed().unwrap(), + "atime of symlink target was unexpectedly modified"); + assert_eq!(exp_target_metadata.modified().unwrap(), target_metadata.modified().unwrap(), + "mtime of symlink target was unexpectedly modified"); +} + +#[test] fn test_futimens() { let tempdir = tempfile::tempdir().unwrap(); let fullpath = tempdir.path().join("file"); |