Repository navigation
Conversation
Check destination ancestors and file/directory collisions before mutating the memory store, preventing copy and mv from creating an inconsistent tree. Assisted-by: OpenAI Codex
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.
Summary
MemoryFileSystem.cp_file inserts directly into its store without validating the destination hierarchy. If /parent is a file, copy("/src", "/parent/child") still succeeds. Afterwards info("/parent") reports a directory while isfile("/parent") is true. mv also removes the original source after creating this invalid destination.
Direct file-to-directory and directory-to-file copies can similarly leave conflicting entries in store and pseudo_dirs.
Validate destination ancestors and the exact destination before changing either collection. The ancestor check uses the same FileExistsError behavior as MemoryFileSystem._open. Ordinary overwrites, missing destination parents, public copy-into-directory behavior, and idempotent directory copies remain supported.
Tests
Regression tests cover cp_file, copy, and mv with file ancestors; explicit and implicit directory destinations; directory-to-file collisions; and unchanged source/destination contents after rejection. Success cases cover normal overwrites and directory copies.
Validation
Checking an implicit destination directory scans the memory store, as existing directory detection does. No remote requests or external services are needed for the new tests.
Assisted-by: OpenAI Codex. The failure was reproduced locally and the code and validation were reviewed before submission.