Skip to content

shutil.copytree emits nonsensical error message for symlinks #102931

@eric-wieser

Description

@eric-wieser

Bug report

The following bash script:

mkdir src_dir
mkdir target_dir
touch src_dir/foo
ln -s $(pwd)/src_dir/foo target_dir/foo
python3 -c "import shutil; shutil.copytree('src_dir', 'target_dir', dirs_exist_ok=True)"

produces the error message

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.8/shutil.py", line 557, in copytree
    return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
  File "/usr/lib/python3.8/shutil.py", line 513, in _copytree
    raise Error(errors)
shutil.Error: ['<', 'D', 'i', 'r', 'E', 'n', 't', 'r', 'y', ' ', "'", 'f', 'o', 'o', "'", '>', ' ', 'a', 'n', 'd', ' ', "'", 't', 'a', 'r', 'g', 'e', 't', '_', 'd', 'i', 'r', '/', 'f', 'o', 'o', "'", ' ', 'a', 'r', 'e', ' ', 't', 'h', 'e', ' ', 's', 'a', 'm', 'e', ' ', 'f', 'i', 'l', 'e']

which has mistakenly converted a string to a list. An error is expected here, but the message is not.

Your environment

  • CPython versions tested on: Python 3.8.10
  • Operating system and architecture: Ubuntu 20.04.5 LTS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions