summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-12-23 11:07:54 (GMT)
committerGitHub <noreply@github.com>2023-12-23 11:07:54 (GMT)
commit6e02d79f96b30bacdbc7a85e42040920b3dee915 (patch)
tree8ccb156e6886c2b2b74992e4a58d326e66931d96 /Lib/shutil.py
parentbdc8d667ab545ccec0bf8c2769f5c5573ed293ea (diff)
downloadcpython-6e02d79f96b30bacdbc7a85e42040920b3dee915.zip
cpython-6e02d79f96b30bacdbc7a85e42040920b3dee915.tar.gz
cpython-6e02d79f96b30bacdbc7a85e42040920b3dee915.tar.bz2
gh-113188: Fix shutil.copymode() on Windows (GH-113189)
Previously it worked differently if dst is a symbolic link: it modified the permission bits of dst itself rather than the file it points to if follow_symlinks is true or src is not a symbolic link, and did nothing if follow_symlinks is false and src is a symbolic link. Also document similar changes in shutil.copystat().
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index dc3aac3..c40f6dd 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -306,7 +306,12 @@ def copymode(src, dst, *, follow_symlinks=True):
else:
return
else:
- stat_func, chmod_func = _stat, os.chmod
+ stat_func = _stat
+ if os.name == 'nt' and os.path.islink(dst):
+ def chmod_func(*args):
+ os.chmod(*args, follow_symlinks=True)
+ else:
+ chmod_func = os.chmod
st = stat_func(src)
chmod_func(dst, stat.S_IMODE(st.st_mode))