diff --git a/Lib/shutil.py b/Lib/shutil.py index ab75ba9da8894b6..5dc0f2ee2f9265a 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -589,6 +589,8 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function, # We can't just leave it to `copy_function` because legacy # code with a custom `copy_function` may rely on copytree # doing the right thing. + if dirs_exist_ok and os.path.lexists(dstname): + os.unlink(dstname) os.symlink(linkto, dstname) copystat(srcobj, dstname, follow_symlinks=not symlinks) else: diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-19-16-30-33.gh-issue-105919.LBV7TS.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-19-16-30-33.gh-issue-105919.LBV7TS.rst new file mode 100644 index 000000000000000..3fc22c064496ed2 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-07-19-16-30-33.gh-issue-105919.LBV7TS.rst @@ -0,0 +1 @@ +fixed shutil.copytree(), now it overrides existing symbolic links correctly