10000 gh-118507 : Refactor `nt._path_is*` by nineteendo · Pull Request #118755 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-118507 : Refactor nt._path_is* #118755

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

Merged
merged 44 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ab76c06
Speedup `ntpath.exists`
nineteendo Apr 13, 2024
1c5350d
Update comment
nineteendo Apr 13, 2024
d7017ac
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 13, 2024
2963338
Improve `nt_exists()`
nineteendo Apr 15, 2024
e833f04
Apply suggestions from code review
nineteendo Apr 15, 2024
d0493c2
Revert helper functions
nineteendo Apr 15, 2024
4403f4a
Update argument clinic
nineteendo Apr 15, 2024
7a9038f
Update 2024-04-13-11-30-09.gh-issue-117841.eW4w_y.rst
nineteendo Apr 22, 2024
a6ec86d
Merge branch 'main' into speedup-ntpath.lexists
nineteendo Apr 26, 2024
30603f0
Refactor `nt._path_is*`
nineteendo May 8, 2024
cd7c6d0
Add `nt._path_isjunction`
nineteendo May 8, 2024
168d299
Fix bug & further refactoring
nineteendo May 8, 2024
e00df4c
Fix attribute name
nineteendo May 8, 2024
b31a252
Add test for pipe
nineteendo May 8, 2024
59e1407
Skip unless `os.pipe` is available
nineteendo May 8, 2024
76acc0d
📜🤖 Added by blurb_it.
blurb-it[bot] May 8, 2024
2c8e464
Update Modules/posixmodule.c
nineteendo May 9, 2024
a8bc5f2
Update Modules/posixmodule.c
nineteendo May 9, 2024
55b6b80
Update Lib/test/test_ntpath.py
nineteendo May 9, 2024
61a62ce
Fix compilation errors
nineteendo May 9, 2024
ba79151
Update Modules/posixmodule.c
nineteendo May 9, 2024
5153413
Merge branch 'refactor-nt._path_is' into speedup-ntpath.lexists
nineteendo May 9, 2024
01568bb
Merge pull request #1 from nineteendo/speedup-ntpath.lexists
nineteendo May 9, 2024
07629c6
Merge news entries
nineteendo May 9, 2024
0fcffb5
Replace ampersand
nineteendo May 9, 2024
cae7a55
More refactoring
nineteendo May 13, 2024
cbf0bc4
Update generated code
nineteendo May 13, 2024
4c0a3f7
Fix path conversion
nineteendo May 13, 2024
5bf963e
Fix undefined variable
nineteendo May 13, 2024
71cb7f0
Add helper function
nineteendo May 13, 2024
24d2749
Apply suggestions from code review
nineteendo May 13, 2024
6edc3b3
Fix syntax error
nineteendo May 13, 2024
c6dae2c
Further refactoring
nineteendo May 13, 2024
05dd20e
Ternary operator
nineteendo May 13, 2024
2ced928
Fix attributes
nineteendo May 13, 2024
dfd4196
No inline
nineteendo May 13, 2024
7a7e942
Apply suggestions from code review
nineteendo May 13, 2024
50b3612
Update posixmodule.c
nineteendo May 13, 2024
eab1cb4
Update Modules/posixmodule.c
nineteendo May 13, 2024
6f6b07b
Update Modules/posixmodule.c
nineteendo May 13, 2024
0ca58a0
Update posixmodule.c
nineteendo May 13, 2024
3f1ea76
Update Modules/posixmodule.c
nineteendo May 13, 2024
222c58a
Update test_ntpath.py
nineteendo May 16, 2024
6e41cbf
Update Lib/test/test_ntpath.py
nineteendo May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update posixmodule.c
  • Loading branch information
nineteendo authored May 13, 2024
commit 50b3612b3e9af236425de239e3aa6cec96d3cdbf
19 changes: 13 additions & 6 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5096,10 +5096,11 @@ os__path_splitroot_impl(PyObject *module, path_t *path)
#define PY_IFRRP 32 // Regular Reparse Point

static BOOL
_testInfo(DWORD attributes, DWORD reparseTag, int testedType)
_testInfo(DWORD attributes, DWORD reparseTag, BOOL diskDevice, int testedType)
{
if (testedType == PY_IFREG) {
return attributes && !(attributes & FILE_ATTRIBUTE_DIRECTORY);
return diskDevice && attributes &&
!(attributes & FILE_ATTRIBUTE_DIRECTORY);
}
if (testedType == PY_IFDIR) {
return attributes & FILE_ATTRIBUTE_DIRECTORY;
Expand Down Expand Up @@ -5131,16 +5132,18 @@ _testFileTypeByHandle(HANDLE hfile, int testedType, BOOL diskOnly)
return FALSE;
}

BOOL diskDevice = GetFileType(hfile) == FILE_TYPE_DISK;
if (testedType != PY_IFREG && testedType != PY_IFDIR) {
FILE_ATTRIBUTE_TAG_INFO info;
return GetFileInformationByHandleEx(hfile, FileAttributeTagInfo, &info,
sizeof(info)) &&
_testInfo(info.FileAttributes, info.ReparseTag, testedType);
_testInfo(info.FileAttributes, info.ReparseTag, diskDevice,
testedType);
}
FILE_BASIC_INFO info;
return GetFileInformationByHandleEx(hfile, FileBasicInfo, &info,
sizeof(info)) &&
_testInfo(info.FileAttributes, 0, testedType);
_testInfo(info.FileAttributes, 0, diskDevice, testedType);
}

static BOOL
Expand All @@ -5154,8 +5157,11 @@ _testFileTypeByName(LPCWSTR path, int testedType)
if (_Py_GetFileInformationByName(path, FileStatBasicByNameInfo, &info,
sizeof(info)))
{
BOOL diskDevice = info.DeviceType == FILE_DEVICE_DISK ||
info.DeviceType == FILE_DEVICE_VIRTUAL_DISK ||
info.DeviceType == FILE_DEVICE_CD_ROM;
BOOL result = _testInfo(info.FileAttributes, info.ReparseTag,
testedType);
diskDevice, testedType);
if (!result || (testedType != PY_IFREG && testedType != PY_IFDIR) ||
!(info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))
{
Expand Down Expand Up @@ -5196,8 +5202,9 @@ _testFileTypeByName(LPCWSTR path, int testedType)
rc = LSTAT(path, &st);
}
if (!rc) {
BOOL diskDevice = GetFileType(hfile) == FILE_TYPE_DISK;
return _testInfo(st.st_file_attributes, st.st_reparse_tag,
testedType);
diskDevice, testedType);
}
}

Expand Down
0