@@ -16,11 +16,11 @@ use jiff::fmt::strtime;
1616use jiff:: tz:: TimeZone ;
1717use jiff:: { Timestamp , ToSpan , Zoned } ;
1818#[ cfg( unix) ]
19- use nix :: libc:: O_NONBLOCK ;
19+ use libc:: O_NONBLOCK ;
2020#[ cfg( unix) ]
21- use nix :: sys :: stat :: futimens ;
21+ use rustix :: fs :: Timestamps ;
2222#[ cfg( unix) ]
23- use nix :: sys :: time :: TimeSpec ;
23+ use rustix :: fs :: futimens ;
2424use std:: borrow:: Cow ;
2525use std:: ffi:: { OsStr , OsString } ;
2626#[ cfg( unix) ]
@@ -617,28 +617,18 @@ fn try_futimens_via_write_fd(path: &Path, atime: FileTime, mtime: FileTime) -> s
617617 . custom_flags ( O_NONBLOCK )
618618 . open ( path) ?;
619619
620- let atime_sec = atime. unix_seconds ( ) ;
621- let atime_nsec = i64:: from ( atime. nanoseconds ( ) ) ;
622- let mtime_sec = mtime. unix_seconds ( ) ;
623- let mtime_nsec = i64:: from ( mtime. nanoseconds ( ) ) ;
624-
625- #[ cfg( target_pointer_width = "32" ) ]
626- let atime_spec = TimeSpec :: new (
627- atime_sec. try_into ( ) . unwrap ( ) ,
628- atime_nsec. try_into ( ) . unwrap ( ) ,
629- ) ;
630- #[ cfg( target_pointer_width = "64" ) ]
631- let atime_spec = TimeSpec :: new ( atime_sec, atime_nsec) ;
632-
633- #[ cfg( target_pointer_width = "32" ) ]
634- let mtime_spec = TimeSpec :: new (
635- mtime_sec. try_into ( ) . unwrap ( ) ,
636- mtime_nsec. try_into ( ) . unwrap ( ) ,
637- ) ;
638- #[ cfg( target_pointer_width = "64" ) ]
639- let mtime_spec = TimeSpec :: new ( mtime_sec, mtime_nsec) ;
640-
641- futimens ( & file, & atime_spec, & mtime_spec) . map_err ( Error :: from)
620+ let timestamps = Timestamps {
621+ last_access : rustix:: fs:: Timespec {
622+ tv_sec : atime. unix_seconds ( ) ,
623+ tv_nsec : atime. nanoseconds ( ) as _ ,
624+ } ,
625+ last_modification : rustix:: fs:: Timespec {
626+ tv_sec : mtime. unix_seconds ( ) ,
627+ tv_nsec : mtime. nanoseconds ( ) as _ ,
628+ } ,
629+ } ;
630+
631+ futimens ( & file, & timestamps) . map_err ( |e| Error :: from_raw_os_error ( e. raw_os_error ( ) ) )
642632}
643633
644634/// Get metadata of the provided path
0 commit comments