| 1780 | } |
| 1781 | |
| 1782 | fn utime_impl( |
| 1783 | path: OsPath, |
| 1784 | acc: Duration, |
| 1785 | modif: Duration, |
| 1786 | dir_fd: DirFd<'_, { UTIME_DIR_FD as usize }>, |
| 1787 | _follow_symlinks: FollowSymlinks, |
| 1788 | vm: &VirtualMachine, |
| 1789 | ) -> PyResult<()> { |
| 1790 | #[cfg(any(target_os = "wasi", unix))] |
| 1791 | { |
| 1792 | #[cfg(not(target_os = "redox"))] |
| 1793 | { |
| 1794 | let path_for_err = path.clone(); |
| 1795 | let path = path.into_cstring(vm)?; |
| 1796 | |
| 1797 | let ts = |d: Duration| libc::timespec { |
| 1798 | tv_sec: d.as_secs() as _, |
| 1799 | tv_nsec: d.subsec_nanos() as _, |
| 1800 | }; |
| 1801 | let times = [ts(acc), ts(modif)]; |
| 1802 | |
| 1803 | let ret = unsafe { |
| 1804 | libc::utimensat( |
| 1805 | dir_fd.get().as_raw(), |
| 1806 | path.as_ptr(), |
| 1807 | times.as_ptr(), |
| 1808 | if _follow_symlinks.0 { |
| 1809 | 0 |
| 1810 | } else { |
| 1811 | libc::AT_SYMLINK_NOFOLLOW |
| 1812 | }, |
| 1813 | ) |
| 1814 | }; |
| 1815 | if ret < 0 { |
| 1816 | Err(OSErrorBuilder::with_filename( |
| 1817 | &io::Error::last_os_error(), |
| 1818 | path_for_err, |
| 1819 | vm, |
| 1820 | )) |
| 1821 | } else { |
| 1822 | Ok(()) |
| 1823 | } |
| 1824 | } |
| 1825 | #[cfg(target_os = "redox")] |
| 1826 | { |
| 1827 | let [] = dir_fd.0; |
| 1828 | |
| 1829 | let tv = |d: Duration| libc::timeval { |
| 1830 | tv_sec: d.as_secs() as _, |
| 1831 | tv_usec: d.as_micros() as _, |
| 1832 | }; |
| 1833 | nix::sys::stat::utimes(path.as_ref(), &tv(acc).into(), &tv(modif).into()) |
| 1834 | .map_err(|err| err.into_pyexception(vm)) |
| 1835 | } |
| 1836 | } |
| 1837 | #[cfg(windows)] |
| 1838 | { |
| 1839 | use std::{fs::OpenOptions, os::windows::prelude::*}; |