-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-101196: Make isdir/isfile/exists faster on Windows #101324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
9a7d3d8
a07f1e7
7765fea
684d683
781fa07
dda7be7
565c2e1
53b932b
f6ce580
88c8b25
39beb86
9d4af5a
1030d8a
be6b592
0e465dc
8fff56b
dcb9513
0d2985d
19018dc
7583a1d
30cf754
c0991ec
3400f07
cb7cea3
636886e
05c9165
5818815
ff6bca9
6d48808
c7128bc
a72aba0
aac93e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -14983,6 +14983,8 @@ os__isdir_impl(PyObject *module, PyObject *path) | |||||||
BOOL close_file = TRUE; | ||||||||
FILE_BASIC_INFO info = { 0 }; | ||||||||
path_t _path = PATH_T_INITIALIZE("isdir", "path", 0, 1); | ||||||||
STRUCT_STAT st; | ||||||||
DWORD error; | ||||||||
int result; | ||||||||
|
||||||||
if (!path_converter(path, &_path)) { | ||||||||
|
@@ -15010,7 +15012,21 @@ os__isdir_impl(PyObject *module, PyObject *path) | |||||||
} | ||||||||
result = info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY; | ||||||||
} else { | ||||||||
result = 0; | ||||||||
error = GetLastError(); | ||||||||
switch (error) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
case ERROR_ACCESS_DENIED: | ||||||||
case ERROR_SHARING_VIOLATION: | ||||||||
case ERROR_CANT_ACCESS_FILE: | ||||||||
case ERROR_INVALID_PARAMETER: | ||||||||
if (win32_stat(_path.wide, &st)) { | ||||||||
mdboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
result = 0; | ||||||||
} else { | ||||||||
result = S_ISDIR(st.st_mode); | ||||||||
} | ||||||||
break; | ||||||||
default: | ||||||||
result = 0; | ||||||||
} | ||||||||
} | ||||||||
Py_END_ALLOW_THREADS | ||||||||
|
||||||||
|
@@ -15043,6 +15059,8 @@ os__isfile_impl(PyObject *module, PyObject *path) | |||||||
BOOL close_file = TRUE; | ||||||||
FILE_BASIC_INFO info = { 0 }; | ||||||||
path_t _path = PATH_T_INITIALIZE("isfile", "path", 0, 1); | ||||||||
STRUCT_STAT st; | ||||||||
DWORD error; | ||||||||
int result; | ||||||||
|
||||||||
if (!path_converter(path, &_path)) { | ||||||||
|
@@ -15073,7 +15091,21 @@ os__isfile_impl(PyObject *module, PyObject *path) | |||||||
CloseHandle(hfile); | ||||||||
} | ||||||||
} else { | ||||||||
result = 0; | ||||||||
error = GetLastError(); | ||||||||
switch (error) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
case ERROR_ACCESS_DENIED: | ||||||||
case ERROR_SHARING_VIOLATION: | ||||||||
case ERROR_CANT_ACCESS_FILE: | ||||||||
case ERROR_INVALID_PARAMETER: | ||||||||
if (win32_stat(_path.wide, &st)) { | ||||||||
mdboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
result = 0; | ||||||||
} else { | ||||||||
result = S_ISREG(st.st_mode); | ||||||||
} | ||||||||
break; | ||||||||
default: | ||||||||
result = 0; | ||||||||
} | ||||||||
} | ||||||||
Py_END_ALLOW_THREADS | ||||||||
|
||||||||
|
@@ -15106,6 +15138,8 @@ os__exists_impl(PyObject *module, PyObject *path) | |||||||
HANDLE hfile; | ||||||||
BOOL close_file = TRUE; | ||||||||
path_t _path = PATH_T_INITIALIZE("exists", "path", 0, 1); | ||||||||
STRUCT_STAT st; | ||||||||
DWORD error; | ||||||||
int result; | ||||||||
|
||||||||
if (!path_converter(path, &_path)) { | ||||||||
|
@@ -15132,7 +15166,21 @@ os__exists_impl(PyObject *module, PyObject *path) | |||||||
CloseHandle(hfile); | ||||||||
} | ||||||||
} else { | ||||||||
result = 0; | ||||||||
error = GetLastError(); | ||||||||
switch (error) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
case ERROR_ACCESS_DENIED: | ||||||||
case ERROR_SHARING_VIOLATION: | ||||||||
case ERROR_CANT_ACCESS_FILE: | ||||||||
case ERROR_INVALID_PARAMETER: | ||||||||
if (win32_stat(_path.wide, &st)) { | ||||||||
mdboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
result = 0; | ||||||||
} else { | ||||||||
erlend-aasland marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
result = 1; | ||||||||
} | ||||||||
break; | ||||||||
default: | ||||||||
result = 0; | ||||||||
} | ||||||||
} | ||||||||
Py_END_ALLOW_THREADS | ||||||||
|
||||||||
|
@@ -15164,6 +15212,8 @@ os__islink_impl(PyObject *module, PyObject *path) | |||||||
BOOL close_file = TRUE; | ||||||||
FILE_ATTRIBUTE_TAG_INFO info = { 0 }; | ||||||||
path_t _path = PATH_T_INITIALIZE("islink", "path", 0, 1); | ||||||||
STRUCT_STAT st; | ||||||||
DWORD error; | ||||||||
int result; | ||||||||
|
||||||||
if (!path_converter(path, &_path)) { | ||||||||
|
@@ -15196,7 +15246,21 @@ os__islink_impl(PyObject *module, PyObject *path) | |||||||
CloseHandle(hfile); | ||||||||
} | ||||||||
} else { | ||||||||
result = 0; | ||||||||
error = GetLastError(); | ||||||||
switch (error) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
case ERROR_ACCESS_DENIED: | ||||||||
case ERROR_SHARING_VIOLATION: | ||||||||
case ERROR_CANT_ACCESS_FILE: | ||||||||
case ERROR_INVALID_PARAMETER: | ||||||||
if (win32_stat(_path.wide, &st)) { | ||||||||
mdboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
result = 0; | ||||||||
} else { | ||||||||
result = S_ISLNK(st.st_mode); | ||||||||
} | ||||||||
break; | ||||||||
default: | ||||||||
result = 0; | ||||||||
} | ||||||||
} | ||||||||
Py_END_ALLOW_THREADS | ||||||||
|
||||||||
|
Uh oh!
There was an error while loading. Please reload this page.