Repository navigation
Conversation
…LLOW_MISSING) On Windows, a path whose non-final component is an existing file fails with ERROR_PATH_NOT_FOUND, which is a FileNotFoundError and was ignored in ALLOW_MISSING mode, so realpath() returned a path that can never be created. Check that the deepest existing prefix is a directory and raise NotADirectoryError otherwise, as posixpath.realpath() does.
Author
|
The macOS Intel failure looks unrelated: the hosted runner lost communication with the server during the build step, so no tests ran. Could someone re-run that job when convenient? Thanks. |
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.
On Windows,
ntpath.realpath()was treating paths that go through a file as if the parent folder was missing. This happens because Windows returnsERROR_PATH_NOT_FOUNDfor both a missing parent and a parent that is actually a file. SinceALLOW_MISSINGignores this error, it wasn't catching this case.I added a check to make sure the deepest existing parent is actually a directory when there's still part of the path left to resolve. This check only runs in strict modes and on paths that have already failed.
With this change,
file\x,file\x\y, andlink-to-file\xnow raiseNotADirectoryErrorfor bothstrandbytespaths. This matches POSIX behaviour and what the documentation already describes.Non-strict mode,
strict=True, andALL_BUT_LASTare unchanged.I also updated some existing assertions in
test_realpath_modethat were expecting the old behaviour. The twoALLOW_MISSINGcases forfile/file2andlink/file2previously asserted the old result.test_posixpath.pyalready expectsNotADirectoryErrorfor these same cases. Changing the Windows tests is part of fixing the inconsistency.This also means
tarfilerejects archive paths that go through a file at the safety filter stage instead of failing later during extraction, matching POSIX behaviour.Testing
Tested on a Windows build of
mainwith Developer Mode enabled, so the symlink cases ran.test_ntpath: 112 run, 3 skipped, 0 failures.ALLOW_MISSINGcases fail without the fix and pass with it.AI assistance: I used AI assistance while working on this change and reviewing the implementation and tests. I reviewed and tested the final changes myself.