Fail renaming a file to or from a path with a trailing separator - #1344
Open
kratos0718 wants to merge 1 commit into
Open
kratos0718 wants to merge 1 commit into
kratos0718 wants to merge 1 commit into
Conversation
Under Posix, os.rename("file", "new/") renamed the file and
os.rename("file/", "new") succeeded, because the trailing separator was
dropped by absnormpath before any check. A trailing separator requires a
directory: Linux raises ENOTDIR, macOS ENOENT, ENOTDIR or EISDIR depending
on the target.
Member
|
Thanks! I'm traveling right now, will review when I get back (in a bit over a week). |
Collaborator
|
|
Collaborator
|
Please also create an issue, that will be referenced in CHANGES.md for the next release. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the changes
Under Posix,
rename()dropped the trailing separator inabsnormpathbefore checking anything, so for a regular filefoo:os.rename("foo", "bar/")renamed the file tobar(the real call fails and leavesfooin place)os.rename("foo", "foo/")succeeded as a no-opos.rename("foo/", "bar")renamed the fileA trailing separator requires a directory. When the source is not a directory and the parent of the target exists, Linux raises
ENOTDIR, while macOS raisesENOENTfor a missing target,EISDIRfor an existing directory andENOTDIRotherwise. A trailing separator on a regular source file raisesENOTDIRon both. Windows is unchanged.I ran the new tests with
TEST_REAL_FS=1on macOS and as a non-root user on Linux (Debian, python 3.13), and they fail without the change. The existing trailing-separator tests for symlinks and directories still pass.Tasks