-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
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
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15143,6 +15143,70 @@ os__exists_impl(PyObject *module, PyObject *path) | |||||
| Py_RETURN_FALSE; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| /*[clinic input] | ||||||
| os._islink | ||||||
|
Contributor
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
|
||||||
|
|
||||||
| path: 'O' | ||||||
|
|
||||||
| Return True if path refers to an existing directory entry that is a symbolic link. | ||||||
|
|
||||||
| Always False if symbolic links are not supported by the Python runtime. | ||||||
|
Contributor
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
Contributor
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. It should be the same as |
||||||
|
|
||||||
| [clinic start generated code]*/ | ||||||
|
|
||||||
| static PyObject * | ||||||
| os__islink_impl(PyObject *module, PyObject *path) | ||||||
|
Contributor
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
|
||||||
| /*[clinic end generated code: output=597174066981ca21 input=df8e74a37ac3c6dc]*/ | ||||||
| { | ||||||
| HANDLE hfile; | ||||||
| BOOL close_file = TRUE; | ||||||
| FILE_ATTRIBUTE_TAG_INFO info = { 0 }; | ||||||
| path_t _path = PATH_T_INITIALIZE("islink", "path", 0, 1); | ||||||
| int result; | ||||||
|
|
||||||
| if (!path_converter(path, &_path)) { | ||||||
| path_cleanup(&_path); | ||||||
| if (PyErr_ExceptionMatches(PyExc_ValueError)) { | ||||||
| PyErr_Clear(); | ||||||
| Py_RETURN_FALSE; | ||||||
| } else { | ||||||
| return NULL; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| Py_BEGIN_ALLOW_THREADS | ||||||
| if (_path.fd != -1) { | ||||||
| hfile = _Py_get_osfhandle_noraise(_path.fd); | ||||||
| close_file = FALSE; | ||||||
| } else { | ||||||
| hfile = CreateFileW(_path.wide, FILE_READ_ATTRIBUTES, 0, NULL, | ||||||
| OPEN_EXISTING, | ||||||
| FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, | ||||||
| NULL); | ||||||
| } | ||||||
| if (hfile != INVALID_HANDLE_VALUE) { | ||||||
| if (GetFileInformationByHandleEx(hfile, FileAttributeTagInfo, &info, sizeof(info))) { | ||||||
| result = (info.ReparseTag == IO_REPARSE_TAG_SYMLINK); | ||||||
| } else { | ||||||
| result = 0; | ||||||
| } | ||||||
| if (close_file) { | ||||||
| CloseHandle(hfile); | ||||||
| } | ||||||
| } else { | ||||||
| result = 0; | ||||||
| } | ||||||
| Py_END_ALLOW_THREADS | ||||||
|
|
||||||
| path_cleanup(&_path); | ||||||
| if (result) { | ||||||
| Py_RETURN_TRUE; | ||||||
| } else { | ||||||
| Py_RETURN_FALSE; | ||||||
| } | ||||||
| } | ||||||
| #endif | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -15335,8 +15399,9 @@ static PyMethodDef posix_methods[] = { | |||||
| OS_SETNS_METHODDEF | ||||||
| OS_UNSHARE_METHODDEF | ||||||
|
|
||||||
| OS__ISFILE_METHODDEF | ||||||
| OS__ISDIR_METHODDEF | ||||||
| OS__ISFILE_METHODDEF | ||||||
| OS__ISLINK_METHODDEF | ||||||
| OS__EXISTS_METHODDEF | ||||||
| {NULL, NULL} /* Sentinel */ | ||||||
| }; | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.