Repository navigation
Conversation
Under Posix, link() looks up the source first, so os.link(missing, existing) raises ENOENT. The fake implementation checked the destination first and raised EEXIST.
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
os.link(src, dst)with a missingsrcand an existingdstraisesEEXISTunder pyfakefs, but the real call raisesENOENT:On Posix,
link()resolves the source before it creates the destination entry. On Linux,do_linkatlooks upoldnamebeforefilename_create(newname).create_linkchecked the destination first.This PR moves the source checks into a small
_resolve_link_sourcehelper:ENOTDIRcheck on the source stays with the lookup, so it keeps its order.I found this with a differential fuzz that runs random sequences of
os/shutilcalls on the real file system and on pyfakefs, then compares the results.Tasks
test_link_bogus_to_existing_file_posix.TEST_REAL_FS=1on macOS.ruff checkandruff format --checkare clean locally.pyfakefs/tests: 1443 passed, 1046 skipped.TEST_REAL_FS=1.AI-assisted (Claude): I used it to help read the code and draft the test. I reviewed and ran everything myself.