mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-111856: Fix os.fstat on windows with FAT32 and exFAT filesystem (GH-112038)
(cherry picked from commit 29af7369db
)
Co-authored-by: AN Long <aisk@users.noreply.github.com>
This commit is contained in:
parent
c6aea46a71
commit
dfdbfc548f
2 changed files with 10 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
Fixes :func:`~os.fstat` on file systems that do not support file ID
|
||||||
|
requests. This includes FAT32 and exFAT.
|
|
@ -1236,6 +1236,7 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
|
||||||
BY_HANDLE_FILE_INFORMATION info;
|
BY_HANDLE_FILE_INFORMATION info;
|
||||||
FILE_BASIC_INFO basicInfo;
|
FILE_BASIC_INFO basicInfo;
|
||||||
FILE_ID_INFO idInfo;
|
FILE_ID_INFO idInfo;
|
||||||
|
FILE_ID_INFO *pIdInfo = &idInfo;
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
|
@ -1268,15 +1269,19 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetFileInformationByHandle(h, &info) ||
|
if (!GetFileInformationByHandle(h, &info) ||
|
||||||
!GetFileInformationByHandleEx(h, FileBasicInfo, &basicInfo, sizeof(basicInfo)) ||
|
!GetFileInformationByHandleEx(h, FileBasicInfo, &basicInfo, sizeof(basicInfo))) {
|
||||||
!GetFileInformationByHandleEx(h, FileIdInfo, &idInfo, sizeof(idInfo))) {
|
|
||||||
/* The Win32 error is already set, but we also set errno for
|
/* The Win32 error is already set, but we also set errno for
|
||||||
callers who expect it */
|
callers who expect it */
|
||||||
errno = winerror_to_errno(GetLastError());
|
errno = winerror_to_errno(GetLastError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Py_attribute_data_to_stat(&info, 0, &basicInfo, &idInfo, status);
|
if (!GetFileInformationByHandleEx(h, FileIdInfo, &idInfo, sizeof(idInfo))) {
|
||||||
|
/* Failed to get FileIdInfo, so do not pass it along */
|
||||||
|
pIdInfo = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
_Py_attribute_data_to_stat(&info, 0, &basicInfo, pIdInfo, status);
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
return fstat(fd, status);
|
return fstat(fd, status);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue