Skip to content
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

shutil.copytree() handles symbolic directory incorrectly #65896

Closed
shajunxing mannequin opened this issue Jun 9, 2014 · 9 comments
Closed

shutil.copytree() handles symbolic directory incorrectly #65896

shajunxing mannequin opened this issue Jun 9, 2014 · 9 comments
Assignees
Labels
easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@shajunxing
Copy link
Mannequin

shajunxing mannequin commented Jun 9, 2014

BPO 21697
Nosy @ned-deily, @takluyver, @berkerpeksag
Files
  • 截图 - 2014年06月09日 - 21时14分13秒.png: shutil.py source code screenshot
  • issue21697.diff
  • issue21697.diff
  • shutil_copytree_symlink_dir.patch: Patch including test
  • 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:

    assignee = 'https://github.com/berkerpeksag'
    closed_at = <Date 2015-07-25.11:58:17.330>
    created_at = <Date 2014-06-09.13:19:19.281>
    labels = ['easy', 'type-bug', 'library']
    title = 'shutil.copytree() handles symbolic directory incorrectly'
    updated_at = <Date 2015-07-25.11:58:17.329>
    user = 'https://bugs.python.org/shajunxing'

    bugs.python.org fields:

    activity = <Date 2015-07-25.11:58:17.329>
    actor = 'berker.peksag'
    assignee = 'berker.peksag'
    closed = True
    closed_date = <Date 2015-07-25.11:58:17.330>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2014-06-09.13:19:19.281>
    creator = 'shajunxing'
    dependencies = []
    files = ['35541', '35614', '35660', '39893']
    hgrepos = []
    issue_num = 21697
    keywords = ['patch', 'easy']
    message_count = 9.0
    messages = ['220088', '220112', '220431', '220758', '224546', '232870', '246587', '247347', '247348']
    nosy_count = 8.0
    nosy_names = ['ned.deily', 'python-dev', 'takluyver', 'berker.peksag', 'puppet', 'Eduardo.Seabra', 'shajunxing', 'Bj\xc3\xb6rn.Dahlgren']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21697'
    versions = ['Python 3.4', 'Python 3.5', 'Python 3.6']

    @shajunxing
    Copy link
    Mannequin Author

    shajunxing mannequin commented Jun 9, 2014

    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.

    @shajunxing shajunxing mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jun 9, 2014
    @ned-deily
    Copy link
    Member

    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?

    @ned-deily ned-deily added the easy label Jun 9, 2014
    @berkerpeksag
    Copy link
    Member

    Here's a patch. I'm getting the following error without modify Lib/shutil.py:

    ======================================================================
    ERROR: test_copytree_symbolic_directory (test.test_shutil.TestShutil)
    ----------------------------------------------------------------------

    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'")]

    @EduardoSeabra
    Copy link
    Mannequin

    EduardoSeabra mannequin commented Jun 16, 2014

    Berker Peksag, I don't think your patch is okay.
    When symlinks is set to true, it should copy the symbolic link of the directory. Your code is calling copytree instead.
    I think the following patch is working, no errors on regression tests.

    @puppet
    Copy link
    Mannequin

    puppet mannequin commented Aug 2, 2014

    I have tested both patches on CentOS 6.4 and Eduardo Seabra:s patch works correctly with symlinks=True

    @BjrnDahlgren
    Copy link
    Mannequin

    BjrnDahlgren mannequin commented Dec 18, 2014

    I ran across this bug too. Applying Eduardo's patch got my package
    working under Py 3.4

    @berkerpeksag berkerpeksag self-assigned this Jul 10, 2015
    @takluyver
    Copy link
    Mannequin

    takluyver mannequin commented Jul 10, 2015

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 25, 2015

    New changeset e807f1d81cb6 by Berker Peksag in branch '3.4':
    Issue bpo-21697: shutil.copytree() now correctly handles symbolic links that point to directories.
    https://hg.python.org/cpython/rev/e807f1d81cb6

    New changeset 31f4041b9286 by Berker Peksag in branch '3.5':
    Issue bpo-21697: shutil.copytree() now correctly handles symbolic links that point to directories.
    https://hg.python.org/cpython/rev/31f4041b9286

    New changeset 8f65be73eb3a by Berker Peksag in branch 'default':
    Issue bpo-21697: shutil.copytree() now correctly handles symbolic links that point to directories.
    https://hg.python.org/cpython/rev/8f65be73eb3a

    @berkerpeksag
    Copy link
    Member

    Thanks for the patches and testing!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants