mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-99726: Improves correctness of stat results for Windows, and uses faster API when available (GH-102149)
This deprecates `st_ctime` fields on Windows, with the intent to change them to contain the correct value in 3.14. For now, they should keep returning the creation time as they always have.
This commit is contained in:
parent
e108af6eca
commit
0f175766e2
10 changed files with 446 additions and 82 deletions
80
Include/internal/pycore_fileutils_windows.h
Normal file
80
Include/internal/pycore_fileutils_windows.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
#ifndef Py_INTERNAL_FILEUTILS_WINDOWS_H
|
||||
#define Py_INTERNAL_FILEUTILS_WINDOWS_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef Py_BUILD_CORE
|
||||
# error "Py_BUILD_CORE must be defined to include this header"
|
||||
#endif
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
|
||||
#if !defined(NTDDI_WIN10_NI) || !(NTDDI_VERSION >= NTDDI_WIN10_NI)
|
||||
typedef struct _FILE_STAT_BASIC_INFORMATION {
|
||||
LARGE_INTEGER FileId;
|
||||
LARGE_INTEGER CreationTime;
|
||||
LARGE_INTEGER LastAccessTime;
|
||||
LARGE_INTEGER LastWriteTime;
|
||||
LARGE_INTEGER ChangeTime;
|
||||
LARGE_INTEGER AllocationSize;
|
||||
LARGE_INTEGER EndOfFile;
|
||||
ULONG FileAttributes;
|
||||
ULONG ReparseTag;
|
||||
ULONG NumberOfLinks;
|
||||
ULONG DeviceType;
|
||||
ULONG DeviceCharacteristics;
|
||||
ULONG Reserved;
|
||||
FILE_ID_128 FileId128;
|
||||
LARGE_INTEGER VolumeSerialNumber;
|
||||
} FILE_STAT_BASIC_INFORMATION;
|
||||
|
||||
typedef enum _FILE_INFO_BY_NAME_CLASS {
|
||||
FileStatByNameInfo,
|
||||
FileStatLxByNameInfo,
|
||||
FileCaseSensitiveByNameInfo,
|
||||
FileStatBasicByNameInfo,
|
||||
MaximumFileInfoByNameClass
|
||||
} FILE_INFO_BY_NAME_CLASS;
|
||||
#endif
|
||||
|
||||
typedef BOOL (WINAPI *PGetFileInformationByName)(
|
||||
PCWSTR FileName,
|
||||
FILE_INFO_BY_NAME_CLASS FileInformationClass,
|
||||
PVOID FileInfoBuffer,
|
||||
ULONG FileInfoBufferSize
|
||||
);
|
||||
|
||||
static inline BOOL _Py_GetFileInformationByName(
|
||||
PCWSTR FileName,
|
||||
FILE_INFO_BY_NAME_CLASS FileInformationClass,
|
||||
PVOID FileInfoBuffer,
|
||||
ULONG FileInfoBufferSize
|
||||
) {
|
||||
static PGetFileInformationByName GetFileInformationByName = NULL;
|
||||
static int GetFileInformationByName_init = -1;
|
||||
|
||||
if (GetFileInformationByName_init < 0) {
|
||||
HMODULE hMod = LoadLibraryW(L"api-ms-win-core-file-l2-1-4");
|
||||
GetFileInformationByName_init = 0;
|
||||
if (hMod) {
|
||||
GetFileInformationByName = (PGetFileInformationByName)GetProcAddress(
|
||||
hMod, "GetFileInformationByName");
|
||||
if (GetFileInformationByName) {
|
||||
GetFileInformationByName_init = 1;
|
||||
} else {
|
||||
FreeLibrary(hMod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GetFileInformationByName_init <= 0) {
|
||||
SetLastError(ERROR_NOT_SUPPORTED);
|
||||
return FALSE;
|
||||
}
|
||||
return GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue