]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117267: Ensure DirEntry.stat().st_ctime still contains creation time during deprec...
authorSteve Dower <steve.dower@python.org>
Wed, 3 Apr 2024 22:14:55 +0000 (23:14 +0100)
committerGitHub <noreply@github.com>
Wed, 3 Apr 2024 22:14:55 +0000 (23:14 +0100)
Misc/NEWS.d/next/Windows/2024-03-28-22-12-00.gh-issue-117267.K_tki1.rst [new file with mode: 0644]
Modules/posixmodule.c

diff --git a/Misc/NEWS.d/next/Windows/2024-03-28-22-12-00.gh-issue-117267.K_tki1.rst b/Misc/NEWS.d/next/Windows/2024-03-28-22-12-00.gh-issue-117267.K_tki1.rst
new file mode 100644 (file)
index 0000000..d322142
--- /dev/null
@@ -0,0 +1,5 @@
+Ensure ``DirEntry.stat().st_ctime`` behaves consistently with
+:func:`os.stat` during the deprecation period of ``st_ctime`` by containing
+the same value as ``st_birthtime``. After the deprecation period,
+``st_ctime`` will be the metadata change time (or unavailable through
+``DirEntry``), and only ``st_birthtime`` will contain the creation time.
index fcac3dbe3553ef6162b77270d4b803ea3ddd457a..5e54cf64cd563ecb9d7eb31bf4a2b483c4c4d440 100644 (file)
@@ -15830,6 +15830,10 @@ DirEntry_from_find_data(PyObject *module, path_t *path, WIN32_FIND_DATAW *dataW)
     find_data_to_file_info(dataW, &file_info, &reparse_tag);
     _Py_attribute_data_to_stat(&file_info, reparse_tag, NULL, NULL, &entry->win32_lstat);
 
+    /* ctime is only deprecated from 3.12, so we copy birthtime across */
+    entry->win32_lstat.st_ctime = entry->win32_lstat.st_birthtime;
+    entry->win32_lstat.st_ctime_nsec = entry->win32_lstat.st_birthtime_nsec;
+
     return (PyObject *)entry;
 
 error: