@@ -1103,53 +1103,36 @@ typedef union {
11031103
11041104
11051105void
1106- _Py_attribute_data_to_stat (BY_HANDLE_FILE_INFORMATION * info , FILE_STANDARD_INFO * standard_info ,
1107- ULONG reparse_tag , FILE_BASIC_INFO * basic_info , FILE_ID_INFO * id_info ,
1106+ _Py_attribute_data_to_stat (FILE_STANDARD_INFO * standard_info , ULONG reparse_tag ,
1107+ FILE_BASIC_INFO * basic_info , FILE_ID_INFO * id_info ,
11081108 struct _Py_stat_struct * result )
11091109{
11101110 memset (result , 0 , sizeof (* result ));
11111111
1112- if (info ) {
1113- result -> st_size = (((__int64 )info -> nFileSizeHigh ) << 32 ) + info -> nFileSizeLow ;
1114- result -> st_nlink = info -> nNumberOfLinks ;
1115- if (!id_info )
1116- result -> st_dev = info -> dwVolumeSerialNumber ;
1117- }
1118- if (standard_info && !info ) {
1119- result -> st_size = standard_info -> EndOfFile .QuadPart ;
1120- result -> st_nlink = standard_info -> NumberOfLinks ;
1121- }
1112+ result -> st_size = standard_info -> EndOfFile .QuadPart ;
1113+ result -> st_nlink = standard_info -> NumberOfLinks ;
11221114
11231115 /* st_ctime is deprecated, but we preserve the legacy value in our caller, not here */
1124- if (basic_info ) {
1125- LARGE_INTEGER_to_time_t_nsec (& basic_info -> CreationTime , & result -> st_birthtime , & result -> st_birthtime_nsec );
1126- LARGE_INTEGER_to_time_t_nsec (& basic_info -> ChangeTime , & result -> st_ctime , & result -> st_ctime_nsec );
1127- LARGE_INTEGER_to_time_t_nsec (& basic_info -> LastWriteTime , & result -> st_mtime , & result -> st_mtime_nsec );
1128- LARGE_INTEGER_to_time_t_nsec (& basic_info -> LastAccessTime , & result -> st_atime , & result -> st_atime_nsec );
1129- } else {
1130- FILE_TIME_to_time_t_nsec (& info -> ftCreationTime , & result -> st_birthtime , & result -> st_birthtime_nsec );
1131- FILE_TIME_to_time_t_nsec (& info -> ftLastWriteTime , & result -> st_mtime , & result -> st_mtime_nsec );
1132- FILE_TIME_to_time_t_nsec (& info -> ftLastAccessTime , & result -> st_atime , & result -> st_atime_nsec );
1133- }
1116+ LARGE_INTEGER_to_time_t_nsec (& basic_info -> CreationTime , & result -> st_birthtime , & result -> st_birthtime_nsec );
1117+ LARGE_INTEGER_to_time_t_nsec (& basic_info -> ChangeTime , & result -> st_ctime , & result -> st_ctime_nsec );
1118+ LARGE_INTEGER_to_time_t_nsec (& basic_info -> LastWriteTime , & result -> st_mtime , & result -> st_mtime_nsec );
1119+ LARGE_INTEGER_to_time_t_nsec (& basic_info -> LastAccessTime , & result -> st_atime , & result -> st_atime_nsec );
11341120
11351121 if (id_info ) {
11361122 result -> st_dev = id_info -> VolumeSerialNumber ;
11371123 id_128_to_ino file_id ;
11381124 file_id .id = id_info -> FileId ;
11391125 result -> st_ino = file_id .st_ino ;
11401126 result -> st_ino_high = file_id .st_ino_high ;
1127+ } else {
1128+ // use these fallback values for systems where it's not possible
1129+ // to obtain VolumeSerialNumber / FileId (e.g. Windows UWP)
1130+ result -> st_dev = 1 ;
1131+ result -> st_ino = basic_info -> CreationTime .QuadPart ;
11411132 }
1142- if (!result -> st_ino && !result -> st_ino_high ) {
1143- /* should only occur for DirEntry_from_find_data, in which case the
1144- index is likely to be zero anyway. */
1145- if (info )
1146- result -> st_ino = (((uint64_t )info -> nFileIndexHigh ) << 32 ) + info -> nFileIndexLow ;
1147- }
1148-
1149- const DWORD fileAttributes = basic_info ? basic_info -> FileAttributes : info -> dwFileAttributes ;
11501133
1151- result -> st_file_attributes = fileAttributes ;
1152- result -> st_mode = attributes_to_mode (fileAttributes );
1134+ result -> st_file_attributes = basic_info -> FileAttributes ;
1135+ result -> st_mode = attributes_to_mode (result -> st_file_attributes );
11531136
11541137 /* bpo-37834: Only actual symlinks set the S_IFLNK flag. But lstat() will
11551138 open other name surrogate reparse points without traversing them. To
@@ -1160,13 +1143,6 @@ _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, FILE_STANDARD_INFO*
11601143 /* set the bits that make this a symlink */
11611144 result -> st_mode = (result -> st_mode & ~S_IFMT ) | S_IFLNK ;
11621145 }
1163-
1164- // For UWP compatibility since is not possible obtain the VolumeSerialNumber
1165- // and FileId due security restriction and App isolation
1166- #ifndef MS_WINDOWS_DESKTOP
1167- result -> st_dev = 1 ;
1168- result -> st_ino = basic_info -> CreationTime .QuadPart ;
1169- #endif
11701146}
11711147
11721148void
@@ -1299,7 +1275,7 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
12991275 pIdInfo = NULL ;
13001276 }
13011277
1302- _Py_attribute_data_to_stat (NULL , & standardInfo , 0 , & basicInfo , pIdInfo , status );
1278+ _Py_attribute_data_to_stat (& standardInfo , 0 , & basicInfo , pIdInfo , status );
13031279 return 0 ;
13041280#else
13051281 return fstat (fd , status );
0 commit comments