Recursively copy a source directory to target.
(source: Path, target: Path)
| 709 | # Originates from py. path.local.copy(), with siginficant trims and adjustments. |
| 710 | # TODO(py38): Replace with shutil.copytree(..., symlinks=True, dirs_exist_ok=True) |
| 711 | def copytree(source: Path, target: Path) -> None: |
| 712 | """Recursively copy a source directory to target.""" |
| 713 | assert source.is_dir() |
| 714 | for entry in visit(source, recurse=lambda entry: not entry.is_symlink()): |
| 715 | x = Path(entry) |
| 716 | relpath = x.relative_to(source) |
| 717 | newx = target / relpath |
| 718 | newx.parent.mkdir(exist_ok=True) |
| 719 | if x.is_symlink(): |
| 720 | newx.symlink_to(os.readlink(x)) |
| 721 | elif x.is_file(): |
| 722 | shutil.copyfile(x, newx) |
| 723 | elif x.is_dir(): |
| 724 | newx.mkdir(exist_ok=True) |