Skip to content

Commit f6666fe

Browse files
committed
fix utime
1 parent a3d638a commit f6666fe

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Lib/test/test_os.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ def _test_utime(self, set_time, filename=None):
817817
self.assertEqual(st.st_atime_ns, atime_ns)
818818
self.assertEqual(st.st_mtime_ns, mtime_ns)
819819

820-
@unittest.expectedFailureIfWindows('TODO: RUSTPYTHON; (AssertionError: 2.002003 != 1.002003 within 1e-06 delta (1.0000000000000002 difference))')
821820
def test_utime(self):
822821
def set_time(filename, ns):
823822
# test the ns keyword parameter
@@ -883,7 +882,6 @@ def set_time(filename, ns):
883882
os.utime(name, dir_fd=dirfd, ns=ns)
884883
self._test_utime(set_time)
885884

886-
@unittest.expectedFailureIfWindows('TODO: RUSTPYTHON; (AssertionError: 2.002003 != 1.002003 within 1e-06 delta (1.0000000000000002 difference))')
887885
def test_utime_directory(self):
888886
def set_time(filename, ns):
889887
# test calling os.utime() on a directory
@@ -912,21 +910,18 @@ def _test_utime_current(self, set_time):
912910
self.assertAlmostEqual(st.st_mtime, current,
913911
delta=delta, msg=msg)
914912

915-
@unittest.expectedFailureIfWindows('TODO: RUSTPYTHON; (AssertionError: 3359485824.516508 != 1679742912.516503 within 0.05 delta (1679742912.000005 difference) : st_time=3359485824.516508, current=1679742912.516503, dt=1679742912.000005)')
916913
def test_utime_current(self):
917914
def set_time(filename):
918915
# Set to the current time in the new way
919916
os.utime(self.fname)
920917
self._test_utime_current(set_time)
921918

922-
@unittest.expectedFailureIfWindows('TODO: RUSTPYTHON; (AssertionError: 3359485824.5186944 != 1679742912.5186892 within 0.05 delta (1679742912.0000052 difference) : st_time=3359485824.5186944, current=1679742912.5186892, dt=1679742912.0000052)')
923919
def test_utime_current_old(self):
924920
def set_time(filename):
925921
# Set to the current time in the old explicit way.
926922
os.utime(self.fname, None)
927923
self._test_utime_current(set_time)
928924

929-
@unittest.expectedFailure # TODO: RUSTPYTHON
930925
def test_utime_nonexistent(self):
931926
now = time.time()
932927
filename = 'nonexistent'
@@ -958,7 +953,6 @@ def test_large_time(self):
958953
os.utime(self.fname, (large, large))
959954
self.assertEqual(os.stat(self.fname).st_mtime, large)
960955

961-
@unittest.expectedFailureIfWindows('TODO: RUSTPYTHON; (AssertionError: NotImplementedError not raised)')
962956
def test_utime_invalid_arguments(self):
963957
# seconds and nanoseconds parameters are mutually exclusive
964958
with self.assertRaises(ValueError):

crates/vm/src/stdlib/os.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,9 +1201,15 @@ pub(super) mod _os {
12011201

12021202
let [] = dir_fd.0;
12031203

1204+
if !_follow_symlinks.0 {
1205+
return Err(vm.new_not_implemented_error(
1206+
"utime: follow_symlinks unavailable on this platform",
1207+
));
1208+
}
1209+
12041210
let ft = |d: Duration| {
1205-
let intervals =
1206-
((d.as_secs() as i64 + 11644473600) * 10_000_000) + (d.as_nanos() as i64 / 100);
1211+
let intervals = ((d.as_secs() as i64 + 11644473600) * 10_000_000)
1212+
+ (d.subsec_nanos() as i64 / 100);
12071213
FILETIME {
12081214
dwLowDateTime: intervals as DWORD,
12091215
dwHighDateTime: (intervals >> 32) as DWORD,
@@ -1216,15 +1222,19 @@ pub(super) mod _os {
12161222
let f = OpenOptions::new()
12171223
.write(true)
12181224
.custom_flags(windows_sys::Win32::Storage::FileSystem::FILE_FLAG_BACKUP_SEMANTICS)
1219-
.open(path)
1220-
.map_err(|err| err.into_pyexception(vm))?;
1225+
.open(&path)
1226+
.map_err(|err| IOErrorBuilder::with_filename(&err, path.clone(), vm))?;
12211227

12221228
let ret = unsafe {
12231229
FileSystem::SetFileTime(f.as_raw_handle() as _, std::ptr::null(), &acc, &modif)
12241230
};
12251231

12261232
if ret == 0 {
1227-
Err(io::Error::last_os_error().into_pyexception(vm))
1233+
Err(IOErrorBuilder::with_filename(
1234+
&io::Error::last_os_error(),
1235+
path,
1236+
vm,
1237+
))
12281238
} else {
12291239
Ok(())
12301240
}

0 commit comments

Comments
 (0)