@@ -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