mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
gh-82367: Use FindFirstFile
Win32 API in ntpath.realpath()
(GH-110298)
* Use `FindFirstFile` Win32 API to fix a bug where `ntpath.realpath()` breaks out of traversing a series of paths where a (handled) `ERROR_ACCESS_DENIED` or `ERROR_SHARING_VIOLATION` occurs. * Update docs to reflect that `ntpath.realpath()` eliminates MS-DOS style names.
This commit is contained in:
parent
2cb62c6437
commit
d33aa18f15
8 changed files with 132 additions and 8 deletions
|
@ -4809,6 +4809,37 @@ cleanup:
|
|||
return result;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
os._findfirstfile
|
||||
path: path_t
|
||||
/
|
||||
A function to get the real file name without accessing the file in Windows.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
os__findfirstfile_impl(PyObject *module, path_t *path)
|
||||
/*[clinic end generated code: output=106dd3f0779c83dd input=0734dff70f60e1a8]*/
|
||||
{
|
||||
PyObject *result;
|
||||
HANDLE hFindFile;
|
||||
WIN32_FIND_DATAW wFileData;
|
||||
WCHAR *wRealFileName;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
hFindFile = FindFirstFileW(path->wide, &wFileData);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (hFindFile == INVALID_HANDLE_VALUE) {
|
||||
path_error(path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wRealFileName = wFileData.cFileName;
|
||||
result = PyUnicode_FromWideChar(wRealFileName, wcslen(wRealFileName));
|
||||
FindClose(hFindFile);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
os._getvolumepathname
|
||||
|
@ -15961,6 +15992,7 @@ static PyMethodDef posix_methods[] = {
|
|||
OS__GETFULLPATHNAME_METHODDEF
|
||||
OS__GETDISKUSAGE_METHODDEF
|
||||
OS__GETFINALPATHNAME_METHODDEF
|
||||
OS__FINDFIRSTFILE_METHODDEF
|
||||
OS__GETVOLUMEPATHNAME_METHODDEF
|
||||
OS__PATH_SPLITROOT_METHODDEF
|
||||
OS__PATH_NORMPATH_METHODDEF
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue