Skip to content

Commit 7221f0c

Browse files
committed
Full remove of BY_HANDLE_FILE_INFORMATION parameter
1 parent 4c18091 commit 7221f0c

2 files changed

Lines changed: 22 additions & 46 deletions

File tree

Modules/posixmodule.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,9 @@ PyOS_AfterFork(void)
829829
#ifdef MS_WINDOWS
830830
/* defined in fileutils.c */
831831
void _Py_time_t_to_FILE_TIME(time_t, int, FILETIME *);
832-
void _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *, FILE_STANDARD_INFO*,
833-
ULONG, FILE_BASIC_INFO *, FILE_ID_INFO *,
834-
struct _Py_stat_struct *);
832+
void _Py_attribute_data_to_stat(FILE_STANDARD_INFO*, ULONG,
833+
FILE_BASIC_INFO*, FILE_ID_INFO*,
834+
struct _Py_stat_struct*);
835835
void _Py_stat_basic_info_to_stat(FILE_STAT_BASIC_INFORMATION *,
836836
struct _Py_stat_struct *);
837837
#endif
@@ -2152,7 +2152,7 @@ win32_xstat_slow_impl(const wchar_t *path, struct _Py_stat_struct *result,
21522152

21532153
return -1;
21542154
}
2155-
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
2155+
if (basicInfo.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
21562156
if (traverse ||
21572157
!IsReparseTagNameSurrogate(tagInfo.ReparseTag)) {
21582158
/* The stat call has to traverse but cannot, so fail. */
@@ -2274,7 +2274,7 @@ win32_xstat_slow_impl(const wchar_t *path, struct _Py_stat_struct *result,
22742274
}
22752275
}
22762276

2277-
_Py_attribute_data_to_stat(NULL, &standardInfo, tagInfo.ReparseTag, &basicInfo, pIdInfo, result);
2277+
_Py_attribute_data_to_stat(&standardInfo, tagInfo.ReparseTag, &basicInfo, pIdInfo, result);
22782278
update_st_mode_from_path(path, basicInfo.FileAttributes, result);
22792279

22802280
cleanup:
@@ -16711,7 +16711,7 @@ DirEntry_from_find_data(PyObject *module, path_t *path, WIN32_FIND_DATAW *dataW)
1671116711
}
1671216712

1671316713
find_data_to_file_info(dataW, &basic_info, &standard_info, &reparse_tag);
16714-
_Py_attribute_data_to_stat(NULL, &standard_info, reparse_tag, &basic_info, NULL, &entry->win32_lstat);
16714+
_Py_attribute_data_to_stat(&standard_info, reparse_tag, &basic_info, NULL, &entry->win32_lstat);
1671516715

1671616716
/* ctime is only deprecated from 3.12, so we copy birthtime across */
1671716717
entry->win32_lstat.st_ctime = entry->win32_lstat.st_birthtime;

Python/fileutils.c

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,53 +1103,36 @@ typedef union {
11031103

11041104

11051105
void
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

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

Comments
 (0)