Skip to content

Commit

Permalink
pythongh-102765: added _Py_GetFileInformationByName to isdir
Browse files Browse the repository at this point in the history
  • Loading branch information
finnagin committed Mar 27, 2023
1 parent 2cdc518 commit b9c4dbe
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4789,6 +4789,8 @@ os__path_isdir_impl(PyObject *module, PyObject *path)
FILE_BASIC_INFO info;
path_t _path = PATH_T_INITIALIZE("isdir", "path", 0, 1);
int result;
BOOL slow_path = TRUE;
FILE_STAT_BASIC_INFORMATION statInfo;

if (!path_converter(path, &_path)) {
path_cleanup(&_path);
Expand All @@ -4800,15 +4802,36 @@ os__path_isdir_impl(PyObject *module, PyObject *path)
}

Py_BEGIN_ALLOW_THREADS
if(_path.wide){
if (_Py_GetFileInformationByName(path, FileStatBasicByNameInfo,
&statInfo, sizeof(statInfo))) {
if (// Cannot use fast path for reparse points ...
!(statInfo.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
) {
slow_path = FALSE;
}
} else {
switch(GetLastError()) {
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
case ERROR_NOT_READY:
case ERROR_BAD_NET_NAME:
/* These errors aren't worth retrying with the slow path */
slow_path = FALSE;
case ERROR_NOT_SUPPORTED:
/* indicates the API couldn't be loaded */
break;
}
}
if (_path.fd != -1) {
hfile = _Py_get_osfhandle_noraise(_path.fd);
close_file = FALSE;
}
else {
else if(slow_path){
hfile = CreateFileW(_path.wide, FILE_READ_ATTRIBUTES, 0, NULL,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
}
if (hfile != INVALID_HANDLE_VALUE) {
if (slow_path && hfile != INVALID_HANDLE_VALUE) {
if (GetFileInformationByHandleEx(hfile, FileBasicInfo, &info,
sizeof(info)))
{
Expand Down

0 comments on commit b9c4dbe

Please sign in to comment.