Copy mode bits from src to dst. If follow_symlinks is not set, symlinks aren't followed if and only if both `src` and `dst` are symlinks. If `lchmod` isn't available (e.g. Linux) this method does nothing.
(src, dst, *, follow_symlinks=True)
| 288 | return dst |
| 289 | |
| 290 | def copymode(src, dst, *, follow_symlinks=True): |
| 291 | """Copy mode bits from src to dst. |
| 292 | |
| 293 | If follow_symlinks is not set, symlinks aren't followed if and only |
| 294 | if both `src` and `dst` are symlinks. If `lchmod` isn't available |
| 295 | (e.g. Linux) this method does nothing. |
| 296 | |
| 297 | """ |
| 298 | sys.audit("shutil.copymode", src, dst) |
| 299 | |
| 300 | if not follow_symlinks and _islink(src) and os.path.islink(dst): |
| 301 | if os.name == 'nt': |
| 302 | stat_func, chmod_func = os.lstat, os.chmod |
| 303 | elif hasattr(os, 'lchmod'): |
| 304 | stat_func, chmod_func = os.lstat, os.lchmod |
| 305 | else: |
| 306 | return |
| 307 | else: |
| 308 | if os.name == 'nt' and os.path.islink(dst): |
| 309 | dst = os.path.realpath(dst, strict=True) |
| 310 | stat_func, chmod_func = _stat, os.chmod |
| 311 | |
| 312 | st = stat_func(src) |
| 313 | chmod_func(dst, stat.S_IMODE(st.st_mode)) |
| 314 | |
| 315 | if hasattr(os, 'listxattr'): |
| 316 | def _copyxattr(src, dst, *, follow_symlinks=True): |