8000 gh-111856: Fix os.fstat on windows with FAT32 and exFAT filesystem (G… · python/cpython@29af736 · GitHub
[go: up one dir, main page]

Skip to content

Commit 29af736

Browse files
authored
gh-111856: Fix os.fstat on windows with FAT32 and exFAT filesystem (GH-112038)
1 parent d2f305d commit 29af736

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixes :func:`~os.fstat` on file systems that do not support file ID
2+
requests. This includes FAT32 and exFAT.

Python/fileutils.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
12391239
BY_HANDLE_FILE_INFORMATION info;
12401240
FILE_BASIC_INFO basicInfo;
12411241
FILE_ID_INFO idInfo;
1242+
FILE_ID_INFO *pIdInfo = &idInfo;
12421243
HANDLE h;
12431244
int type;
12441245

@@ -1271,15 +1272,19 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
12711272
}
12721273

12731274
if (!GetFileInformationByHandle(h, &info) ||
1274-
!GetFileInformationByHandleEx(h, FileBasicInfo, &basicInfo, sizeof(basicInfo)) ||
1275-
!GetFileInformationByHandleEx(h, FileIdInfo, &idInfo, sizeof(idInfo))) {
1275+
!GetFileInformationByHandleEx(h, FileBasicInfo, &basicInfo, sizeof(basicInfo))) {
12761276
/* The Win32 error is already set, but we also set errno for
12771277
callers who expect it */
12781278
errno = winerror_to_errno(GetLastError());
12791279
return -1;
12801280
}
12811281

1282-
_Py_attribute_data_to_stat(&info, 0, &basicInfo, &idInfo, status);
1282+
if (!GetFileInformationByHandleEx(h, FileIdInfo, &idInfo, sizeof(idInfo))) {
1283+
/* Failed to get FileIdInfo, so do not pass it along */
1284+
pIdInfo = NULL;
1285+
}
1286+
1287+
_Py_attribute_data_to_stat(&info, 0, &basicInfo, pIdInfo, status);
12831288
return 0;
12841289
#else
12851290
return fstat(fd, status);

0 commit comments

Comments
 (0)
0