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)
| 353 | return dst |
| 354 | |
| 355 | def copymode(src, dst, *, follow_symlinks=True): |
| 356 | """Copy mode bits from src to dst. |
| 357 | |
| 358 | If follow_symlinks is not set, symlinks aren't followed if and only |
| 359 | if both `src` and `dst` are symlinks. If `lchmod` isn't available |
| 360 | (e.g. Linux) this method does nothing. |
| 361 | |
| 362 | """ |
| 363 | sys.audit("shutil.copymode", src, dst) |
| 364 | |
| 365 | if not follow_symlinks and _islink(src) and os.path.islink(dst): |
| 366 | if hasattr(os, 'lchmod'): |
| 367 | stat_func, chmod_func = os.lstat, os.lchmod |
| 368 | else: |
| 369 | return |
| 370 | else: |
| 371 | stat_func = _stat |
| 372 | if os.name == 'nt' and os.path.islink(dst): |
| 373 | def chmod_func(*args): |
| 374 | os.chmod(*args, follow_symlinks=True) |
| 375 | else: |
| 376 | chmod_func = os.chmod |
| 377 | |
| 378 | st = stat_func(src) |
| 379 | chmod_func(dst, stat.S_IMODE(st.st_mode)) |
| 380 | |
| 381 | if hasattr(os, 'listxattr'): |
| 382 | def _copyxattr(src, dst, *, follow_symlinks=True): |
no test coverage detected
searching dependent graphs…