-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Windows: os.stat() returns random times on ERROR_ACCESS_DENIED #114273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
>>> time.gmtime(1705600376.5800736)
time.struct_time(tm_year=2024, tm_mon=1, tm_mday=18, tm_hour=17, tm_min=52, tm_sec=56, tm_wday=3, tm_yday=18, tm_isdst=0) It is approximately the time of the report. Perhaps the time of the request. >>> time.gmtime(-11644246396.230042)
time.struct_time(tm_year=1601, tm_mon=1, tm_mday=3, tm_hour=15, tm_min=6, tm_sec=43, tm_wday=2, tm_yday=3, tm_isdst=0) It is suspiciously close to the start of Win32 epoch https://devblogs.microsoft.com/oldnewthing/20090306-00/?p=18913. @vstinner, were there some changes in time conversion that can be related to this? Or maybe Python 3.11 and 3.12 executables have different capabilities, so Win32 API returns different result? cc @zooba |
- A negative timestamp may be returned by os.stat() for an inaccessible file in Python 3.12: python/cpython#114273 - Add datetime to template global.
On Windows, DWORD access = FILE_READ_ATTRIBUTES;
DWORD flags = FILE_FLAG_BACKUP_SEMANTICS; /* Allow opening directories. */
if (!traverse) {
flags |= FILE_FLAG_OPEN_REPARSE_POINT;
}
hFile = CreateFileW(path, access, 0, NULL, OPEN_EXISTING, flags, NULL);
In short, In fact, |
Note: |
This is fixed in 3.13 already. See #111877. |
It's also been backported, so the next 3.12 will have the fix. I think it missed the last update because of a lack of reviewers. |
I confirm that the fix works as expected. On the current main branch, I also confirm that the code works as expected in the current 3.11 and 3.12 branches. |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
When retrieving the timestamp of an inaccessible file (or directory) in Windows, such as:
, a negative value such as
-11644246396.230042
is returned in Python 3.12.In Python < 3.12, a normal timestamp such as
1705600376.5800736
is returned instead.This may break many scripts as most of them don't expect a negative value.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
The text was updated successfully, but these errors were encountered: