-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
shutil.copytree() handles symbolic directory incorrectly #65896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
While using shutil.copytree() and the source containing symbolic directory (not symbolic file), an error will be raised. I checked the source code and found an obvlous mistake: shutil.copytree() using os.path.islink() to checker whether the source is a symbolic link, it's okay, but after doing this, os.path.isdir() should be called because a symbolic link may either be a file or a directry, shutil.copytree() just treated all of them as file, and invoke copy_function to copy it, so error happens. I don't know whether newer versions have fixed this bug, but I googled it and found nothing. |
Thanks for the report. The bug is still present in the 3.4 and default (what will become the 3.5 release) branches; the 3.3 branch now only accepts security fixes. 2.7 does not fail. Would you be interested in producing a patch for the problem? |
Here's a patch. I'm getting the following error without modify Lib/shutil.py: ====================================================================== Traceback (most recent call last):
File "/home/berker/projects/cpython-default/Lib/test/test_shutil.py", line 650, in test_copytree_symbolic_directory
shutil.copytree(src_dir, dst_dir)
File "/home/berker/projects/cpython-default/Lib/shutil.py", line 342, in copytree
raise Error(errors)
shutil.Error: [('/tmp/tmpiy30_34s/src/link', '/tmp/tmpiy30_34s/dst/link', "[Errno 21] Is a directory: '/tmp/tmpiy30_34s/src/link'")] |
Berker Peksag, I don't think your patch is okay. |
I have tested both patches on CentOS 6.4 and Eduardo Seabra:s patch works correctly with symlinks=True |
I ran across this bug too. Applying Eduardo's patch got my package |
Here's my patch (I submitted the duplicate issue). I think it's functionally the same as Eduardo's, but it also adds a test. |
New changeset e807f1d81cb6 by Berker Peksag in branch '3.4': New changeset 31f4041b9286 by Berker Peksag in branch '3.5': New changeset 8f65be73eb3a by Berker Peksag in branch 'default': |
Thanks for the patches and testing! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: