Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GH-118289: Fix handling of non-directories in posixpath.realpath() #120127

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 4 commits into from
Nov 13, 2024

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented Jun 5, 2024

In strict mode, raise NotADirectoryError if we encounter a non-directory while we still have path parts left to process.

We use a part_count variable rather than len(rest) because the rest stack also contains markers for unresolved symlinks.

In strict mode, raise `NotADirectoryError` if we encounter a non-directory
while we still have path parts left to process.

We use a `part_count` variable rather than `len(rest)` because the `rest`
stack also contains markers for unresolved symlinks.
@barneygale
Copy link
Contributor Author

Follow-up to #118290, where I messed up a rebase and notified everyone (whoops!)

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

How does it work on Windows? Could you add generic tests for these cases?

@nineteendo

This comment was marked as outdated.

@barneygale
Copy link
Contributor Author

barneygale commented Nov 13, 2024

Thanks for the review, Serhiy. Playing around with this in Windows, it seems that nt._getfinalpathname() resolves features like . and .. segments, and extraneous slashes (such as trailing slashes) up-front, rather than progressively like POSIX does. Also, it can raise FileNotFoundError rather than NotADirectoryError when treating a file as a directory. So I think the issue is pretty POSIX-specific.

@barneygale barneygale changed the title GH-118289: Fix handling of non-directories in os.path.realpath() GH-118289: Fix handling of non-directories in posixpath.realpath() Nov 13, 2024
@barneygale barneygale enabled auto-merge (squash) November 13, 2024 22:05
@barneygale barneygale merged commit fd4b545 into python:main Nov 13, 2024
36 checks passed
@miss-islington-app
Copy link

Thanks @barneygale for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @barneygale, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker fd4b5453df74e249987553b12c14ad75fafa4991 3.13

barneygale added a commit to barneygale/cpython that referenced this pull request Nov 13, 2024
….realpath()` (pythonGH-120127)

In strict mode, raise `NotADirectoryError` if we encounter a non-directory
while we still have path parts left to process.

We use a `part_count` variable rather than `len(rest)` because the `rest`
stack also contains markers for unresolved symlinks..
(cherry picked from commit fd4b545)

Co-authored-by: Barney Gale <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Nov 13, 2024

GH-126815 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Nov 13, 2024
barneygale added a commit that referenced this pull request Nov 13, 2024
…ath()` (GH-120127) (#126815)

In strict mode, raise `NotADirectoryError` if we encounter a non-directory
while we still have path parts left to process.

We use a `part_count` variable rather than `len(rest)` because the `rest`
stack also contains markers for unresolved symlinks.
(cherry picked from commit fd4b545)
picnixz pushed a commit to picnixz/cpython that referenced this pull request Dec 8, 2024
…th()` (python#120127)

In strict mode, raise `NotADirectoryError` if we encounter a non-directory
while we still have path parts left to process.

We use a `part_count` variable rather than `len(rest)` because the `rest`
stack also contains markers for unresolved symlinks.
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
…th()` (python#120127)

In strict mode, raise `NotADirectoryError` if we encounter a non-directory
while we still have path parts left to process.

We use a `part_count` variable rather than `len(rest)` because the `rest`
stack also contains markers for unresolved symlinks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants