Bug report
Bug description:
We are switching our product to Python 3.12 from Python 3.11.2 and our tests caught a difference in the way os.stat works under Windows. It returns negative values of st_atime, st_mtime, and st_ctime if there are no permissions assigned to the file.
How to reproduce: you can remove all permissions using Windows Explorer, right-click on a file, select "Properties", select "Security" tab, press "Edit" button, and finally remove all entries from the "Group and user names" list. Or remove all inherited permissions in "Properties / Security /Advanced" window, icacls should show an empty list of permissions, for example:
PS C:\...> icacls a.txt
a.txt
Successfully processed 1 files; Failed processing 0 files
and then check the output in Python 3.12:
(python-312) PS C:\...> python -c "import os; print(os.stat('a.txt'))"
os.stat_result(st_mode=33206, st_ino=0, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0, st_atime=-11644473600, st_mtime=-11644473600, st_ctime=-11644473600)
and the same for Python 3.11.2, which is correct:
(python-311) PS C:\...> python -c "import os; print(os.stat('a.txt'))"
os.stat_result(st_mode=33206, st_ino=0, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0, st_atime=1699527432, st_mtime=1699527008, st_ctime=1699527008)
The returned value sounds like secs_between_epochs from https://github.com/python/cpython/blob/main/Python/fileutils.c#L1050 Maybe it has something to do with the issue.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
Bug report
Bug description:
We are switching our product to Python 3.12 from Python 3.11.2 and our tests caught a difference in the way
os.statworks under Windows. It returns negative values ofst_atime,st_mtime, andst_ctimeif there are no permissions assigned to the file.How to reproduce: you can remove all permissions using Windows Explorer, right-click on a file, select "Properties", select "Security" tab, press "Edit" button, and finally remove all entries from the "Group and user names" list. Or remove all inherited permissions in "Properties / Security /Advanced" window,
icaclsshould show an empty list of permissions, for example:and then check the output in Python 3.12:
and the same for Python 3.11.2, which is correct:
The returned value sounds like
secs_between_epochsfrom https://github.com/python/cpython/blob/main/Python/fileutils.c#L1050 Maybe it has something to do with the issue.CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs