Sha256: 574254c70a935ca5180b0d18dd7ed4a14c74ad4d0418254f9c7307a4e29c219a
Contents?: true
Size: 1.94 KB
Versions: 6
Compression:
Stored size: 1.94 KB
Contents
use crate::fs::SystemTimeSpec; use crate::time::SystemClock; use io_lifetimes::BorrowedFd; use rustix::fs::{utimensat, AtFlags, Timestamps, UTIME_NOW, UTIME_OMIT}; use rustix::time::Timespec; use std::convert::TryInto; use std::path::Path; use std::{fs, io}; #[allow(clippy::useless_conversion)] fn to_timespec(ft: Option<SystemTimeSpec>) -> io::Result<Timespec> { Ok(match ft { None => Timespec { tv_sec: 0, tv_nsec: UTIME_OMIT.into(), }, Some(SystemTimeSpec::SymbolicNow) => Timespec { tv_sec: 0, tv_nsec: UTIME_NOW.into(), }, Some(SystemTimeSpec::Absolute(ft)) => { let duration = ft.duration_since(SystemClock::UNIX_EPOCH).unwrap(); let nanoseconds = duration.subsec_nanos(); assert_ne!(i64::from(nanoseconds), i64::from(UTIME_OMIT)); assert_ne!(i64::from(nanoseconds), i64::from(UTIME_NOW)); Timespec { tv_sec: duration .as_secs() .try_into() .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?, tv_nsec: nanoseconds.try_into().unwrap(), } } }) } pub(crate) fn set_times_nofollow_unchecked( start: &fs::File, path: &Path, atime: Option<SystemTimeSpec>, mtime: Option<SystemTimeSpec>, ) -> io::Result<()> { let times = Timestamps { last_access: to_timespec(atime)?, last_modification: to_timespec(mtime)?, }; Ok(utimensat(start, path, ×, AtFlags::SYMLINK_NOFOLLOW)?) } #[allow(dead_code)] pub(crate) fn set_times_follow_unchecked( start: BorrowedFd<'_>, path: &Path, atime: Option<SystemTimeSpec>, mtime: Option<SystemTimeSpec>, ) -> io::Result<()> { let times = Timestamps { last_access: to_timespec(atime)?, last_modification: to_timespec(mtime)?, }; Ok(utimensat(&start, path, ×, AtFlags::empty())?) }
Version data entries
6 entries across 6 versions & 1 rubygems