shutil_g.copytree: fix infinite recursion bug (#1925) #3147
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.
ISSUE TYPE
x Bug fix
RUNTIME ENVIRONMENT
CHECKLIST
CONTRIBUTINGdocument has been read [REQUIRED]DESCRIPTION
Record the destination directory in a set of "ignored trees" and pass this variable down to recursive instances of
copytree().Remove the
ignorekeyword argument mostly because Pylint complains that the function is too big otherwise. Fortunately it was never used anyway.MOTIVATION AND CONTEXT
When copying a folder into its subtree,
copytree()willrecursively copy the newly created directory, and enter an infinite recursive descent, because it doesn't know which of the files it already created.
This is somewhat of an edge case and some file managers outright refuse to handle it. Even the version of
cprunning on my machine won't do this. But it seems like a simple bug for us to fix and it'd give the user more freedom.#1925
TESTING
Create a directory, and create another directory inside of it.
Optionally create additional files and add them to either directory.
Now copy the first directory (
:copy), navigate into the second directoy, and run the:pastecommand. All the contents of the source directory will be in the second directory as a user would expect.Changes to
shutil_generatorizedaffect theCopyLoaderclass, which is its only user. The specific code paths involved would only affect copying directories using:copyfollowed by:paste.