summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-05-29 16:57:04 (GMT)
committerGitHub <noreply@github.com>2023-05-29 16:57:04 (GMT)
commit68bf3fe0e4221bd33823b727af1f70708bdb8f29 (patch)
tree66b9ac4ded084f30b702d332bcbd4d07b0661122 /Modules/posixmodule.c
parent635ce29257a7f7272af009d3c08379522317d89b (diff)
downloadcpython-68bf3fe0e4221bd33823b727af1f70708bdb8f29.zip
cpython-68bf3fe0e4221bd33823b727af1f70708bdb8f29.tar.gz
cpython-68bf3fe0e4221bd33823b727af1f70708bdb8f29.tar.bz2
gh-104820: Fixes os.stat on Windows to better handle file systems that do not support FileIdInformation (GH-104892)
(cherry picked from commit 6031727a37c6003f78e3b0c7414a0a214855dd08) Co-authored-by: Steve Dower <steve.dower@python.org>
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 77df9e7..abc50b4 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1864,6 +1864,7 @@ win32_xstat_slow_impl(const wchar_t *path, struct _Py_stat_struct *result,
BY_HANDLE_FILE_INFORMATION fileInfo;
FILE_BASIC_INFO basicInfo;
FILE_ID_INFO idInfo;
+ FILE_ID_INFO *pIdInfo = &idInfo;
FILE_ATTRIBUTE_TAG_INFO tagInfo = { 0 };
DWORD fileType, error;
BOOL isUnhandledTag = FALSE;
@@ -2000,9 +2001,7 @@ win32_xstat_slow_impl(const wchar_t *path, struct _Py_stat_struct *result,
if (!GetFileInformationByHandle(hFile, &fileInfo) ||
!GetFileInformationByHandleEx(hFile, FileBasicInfo,
- &basicInfo, sizeof(basicInfo)) ||
- !GetFileInformationByHandleEx(hFile, FileIdInfo,
- &idInfo, sizeof(idInfo))) {
+ &basicInfo, sizeof(basicInfo))) {
switch (GetLastError()) {
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_FUNCTION:
@@ -2018,7 +2017,12 @@ win32_xstat_slow_impl(const wchar_t *path, struct _Py_stat_struct *result,
}
}
- _Py_attribute_data_to_stat(&fileInfo, tagInfo.ReparseTag, &basicInfo, &idInfo, result);
+ if (!GetFileInformationByHandleEx(hFile, FileIdInfo, &idInfo, sizeof(idInfo))) {
+ /* Failed to get FileIdInfo, so do not pass it along */
+ pIdInfo = NULL;
+ }
+
+ _Py_attribute_data_to_stat(&fileInfo, tagInfo.ReparseTag, &basicInfo, pIdInfo, result);
update_st_mode_from_path(path, fileInfo.dwFileAttributes, result);
cleanup: