You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shutil.copytree() fails to override existing symbolic links #105919
Per documentation shutil.copytree() with dirs_exist_ok=True should override all the files. However, shutil.copytree() fails to override existing symbolic links to files in the directory structure.
import os
import shutil
#cleanup
if os.path.isdir('src'):
shutil.rmtree('src')
if os.path.isdir('dst'):
shutil.rmtree('dst')
os.mkdir('src')
os.mkdir('src/dir')
os.mkdir('dst')
with open('src/top.txt', "w") as constrs:
constrs.write("dummy")
if not os.path.exists('src/dir/link'):
if os.path.isfile(os.path.join(os.getcwd(),'src/top.txt')):
os.symlink('../top.txt', 'src/dir/link')
#Inital copy to empty location. Here it works as there is no link in the destination
shutil.copytree('src', 'dst', symlinks=True, ignore=None, dirs_exist_ok=True, ignore_dangling_symlinks=True)
#2nd launch, fails to override the symlink and results in an error
shutil.copytree('src', 'dst', symlinks=True, ignore=None, dirs_exist_ok=True, ignore_dangling_symlinks=True)
Environment
Python versions tested on: 3.11.2,
Operating system : RHEL 7.9 (Maipo), 3.10.0-1160.76.1.el7.x86_64
@SPnRD Use triple backticks ``` above and below code and traceback blocks to format properly, including indents.
I redid both above. Click ... on title bar and select `edit` to see raw text.
My participation was strictly as triager helping OP format code. @giampaolo still active?
One of you should use git blame to see who has worked on shutil more recently than giampaolo. (I likely have never done so.) When found, ping here and request review on the PR.
I am also having this issue. This is counter intuitive as in documentation it is said that dirs_exist_ok=True will overwrite anything if exists. But I am getting error where it is not being able to overwrite symlinks to files(I didn't checked symlinks to directories). I am getting similar error saying that file already exists...
Activity
terryjreedy commentedon Jun 20, 2023
@SPnRD Use triple backticks ``` above and below code and traceback blocks to format properly, including indents.
I redid both above. Click
...on title bar and select `edit` to see raw text.gaitovrat commentedon Jul 31, 2024
@terryjreedy Any progress here?
athre4t commentedon Jul 31, 2024
@terryjreedy Any progress here?
terryjreedy commentedon Aug 1, 2024
My participation was strictly as triager helping OP format code.
@giampaolo still active?
One of you should use git blame to see who has worked on shutil more recently than giampaolo. (I likely have never done so.) When found, ping here and request review on the PR.
gaitovrat commentedon Aug 1, 2024
@barneygale could you review the PR?
Rid1FZ commentedon Sep 11, 2024
I am also having this issue. This is counter intuitive as in documentation it is said that
dirs_exist_ok=Truewill overwrite anything if exists. But I am getting error where it is not being able to overwrite symlinks to files(I didn't checked symlinks to directories). I am getting similar error saying that file already exists...