You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I agree that all of these _path_is* and _path_[l]exists helpers are a lot of code to maintain, taken together. It could be refactored into smaller inline helper functions that can be reused, which would also make the code more readable.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
My goal was to remove duplicated code and divide the work into two separate operations that can be understood and modified independently, written in a way that I think is easy to understand. This reduces the maintenance burden. I also added internal support for checking for mount points, in case we implement _path_isjunction().
I added a GetFileType() check in the by-handle code. When combined with the diskOnly parameter, the GetFileType() check makes it safer to check an open file descriptor since the check is implemented directly in the I/O manager without trying to acquire the file lock. If GetFileInformationByHandleEx() is called on a handle for a synchronous-mode pipe, it could block indefinitely. For example, with the current implementation in 3.12:
Also, given the system's named-pipe filesystem (NPFS) support for basic file information (anonymous pipes are also in NPFS, but they're like unlinked open files in POSIX), the GetFileType() check avoids classifying pipes as regular files. Again, with the current implementation in 3.12:
Activity
nineteendo commentedon May 6, 2024
Eryk, do you have any ideas to clean them up (besides the simpler error handling)?
eryksun commentedon May 7, 2024
nineteendo commentedon May 7, 2024
Good start, we probably need a
follow_symlinksoption for_testFileTypeByNameto useLSTAT()though.eryksun commentedon May 7, 2024
eryksun commentedon May 7, 2024
nineteendo commentedon May 8, 2024
Did you speed something up, because it's only 3 lines less than the old code.
eryksun commentedon May 8, 2024
My goal was to remove duplicated code and divide the work into two separate operations that can be understood and modified independently, written in a way that I think is easy to understand. This reduces the maintenance burden. I also added internal support for checking for mount points, in case we implement
_path_isjunction().I added a
GetFileType()check in the by-handle code. When combined with thediskOnlyparameter, theGetFileType()check makes it safer to check an open file descriptor since the check is implemented directly in the I/O manager without trying to acquire the file lock. IfGetFileInformationByHandleEx()is called on a handle for a synchronous-mode pipe, it could block indefinitely. For example, with the current implementation in 3.12:Also, given the system's named-pipe filesystem (NPFS) support for basic file information (anonymous pipes are also in NPFS, but they're like unlinked open files in POSIX), the
GetFileType()check avoids classifying pipes as regular files. Again, with the current implementation in 3.12:>>> pr, pw = os.pipe() >>> os.path.isfile(pr) Truenineteendo commentedon May 8, 2024
OK, that explains why the code isn't much shorter. I added a test for the second issue. The first one seems difficult to test.
gh-118507 : Refactor `nt._path_is*` to improve applicability for othe…
pythongh-118507 : Refactor `nt._path_is*` to improve applicability fo…
gh-118507 : Refactor `nt._path_is*` to improve applicability for othe…
pythongh-118507 : Refactor `nt._path_is*` to improve applicability fo…
gh-118507 : Refactor ntpath native functions (gh-119381)
gh-118507: Amend news entry to mention ntpath.isfile bugfix (GH-120817)
pythongh-118507: Amend news entry to mention ntpath.isfile bugfix
gh-118507: Amend news entry to mention ntpath.isfile bugfix (GH-120817)
pythongh-118507: Amend news entry to mention ntpath.isfile bugfix (py…
pythongh-118507 : Refactor `nt._path_is*` to improve applicability fo…
pythongh-118507: Amend news entry to mention ntpath.isfile bugfix (py…