gh-99547: Add isjunction methods for checking if a path is a junction#99548
gh-99547: Add isjunction methods for checking if a path is a junction#99548zooba merged 44 commits intopython:mainfrom
Conversation
The actual functionality lives in ntpath/posixpath, so just verify the correct function is called and return value is returned
…latforms We can only create junctions on windows, thus only test this on win32
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Eryk Sun <eryksun@gmail.com>
ntpath can be used on POSIX, even though the stat_result won't have st_reparse_tag. Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Eryk Sun <eryksun@gmail.com>
|
Code looks good, but we'll also need docs updated (at least the os.path docs and What's New for 3.12) |
|
@zooba is there a wiki or something on which files generate the docs? I had thought maybe it was from the code. Happy to update docs :) |
|
Whelp.. doing this on a phone is tough.. reopened |
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Eryk Sun <eryksun@gmail.com>
|
|
We could eliminate try:
is_dir = (entry.is_dir(follow_symlinks=False) and
not entry.is_junction())
except OSError:
is_dir = FalseThis is relatively cheap. On Windows, both tests use the cached stat info from the directory entry. On POSIX, the To replace if os.path.islink(path) or os.path.isjunction(path):
# symlinks to directories are forbidden, see bug #1669
raise OSError("Cannot call rmtree on a symbolic link or junction")However, this calls If |
|
I'm not a big fan of needing to call stat again if we don't need to. Part of me thinks that stat objects should have methods similar to pathlib.Path's is_ methods for checking things based on a cached stat. We can kind of cheat to get there with a DirEntry but idk. I mean I know we have some stat IS_ functions but I guess I like methods on objects better than loose functions. Regardless: do we feel as though these optimizations should be part of the current issue or should maybe be a post merge task? I kind of feel as though we're stepping a tiny bit out of the scope of the current task. |
|
I don't consider the |
Replacing
Junctions don't have a POSIX file type other than as a directory, |
|
It's just continually adding things on to the same PR is kind of discouraging for me as a new contributor. I'd greatly prefer having all asks at once (so they can be attacked at once) as opposed to small ones continually given over and over. |
Okay. I'm sorry if you feel discouraged. This pull request is outstanding for a new contributor. |
|
@zooba, since your last review there was a minor change to the documentation, and a test was fixed. If that's all okay with you, then this is ready to be merged as soon as Charles says so. |
… dir and not a junction across the board
|
Ok i removed _rmtree_is_dir() and replaced its usage with is_dir/is_junction checks. Unit tests pass. If its ok, i'm good with a merge at this point. |
Co-authored-by: Eryk Sun <eryksun@gmail.com>
|
I wonder if one day is_dir should be updated to return False on OSError internally.. regardless I've updated the implementation to handle that case here. I'll leave that to a separate thread. Updated. If it all passes, i'm still good for merge here. |
The rationale is in PEP 471, notes on exception handling. |
Co-authored-by: Eryk Sun <eryksun@gmail.com>
|
Thanks! Great job, and congratulations on your first contribution! |
Implementation of gh-99547.
This is my first try at getting something into cpython.. so please go easy on me. Thanks!