Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,13 @@ def set_time(filename):
os.utime(self.fname, None)
self._test_utime_current(set_time)

def test_utime_nonexistent(self):
now = time.time()
filename = 'nonexistent'
with self.assertRaises(FileNotFoundError) as cm:
os.utime(filename, (now, now))
self.assertEqual(cm.exception.filename, filename)

def get_file_system(self, path):
if sys.platform == 'win32':
root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Exceptions raised by os.utime builtin function now include the related
filename
9 changes: 2 additions & 7 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6307,11 +6307,7 @@ os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
_Py_time_t_to_FILE_TIME(utime.mtime_s, utime.mtime_ns, &mtime);
}
if (!SetFileTime(hFile, NULL, &atime, &mtime)) {
/* Avoid putting the file name into the error here,
as that may confuse the user into believing that
something is wrong with the file, when it also
could be the time stamp that gives a problem. */
PyErr_SetFromWindowsErr(0);
path_error(path);
CloseHandle(hFile);
return NULL;
}
Expand Down Expand Up @@ -6351,8 +6347,7 @@ os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
#endif

if (result < 0) {
/* see previous comment about not putting filename in error here */
posix_error();
path_error(path);
return NULL;
}

Expand Down