copy a given file or directory to a given path, overwriting the destination
(from_path: Union[str, Path], to_path: Union[str, Path])
| 130 | |
| 131 | @enforce_types |
| 132 | def copy_and_overwrite(from_path: Union[str, Path], to_path: Union[str, Path]): |
| 133 | """copy a given file or directory to a given path, overwriting the destination""" |
| 134 | if Path(from_path).is_dir(): |
| 135 | shutil.rmtree(to_path, ignore_errors=True) |
| 136 | shutil.copytree(from_path, to_path) |
| 137 | else: |
| 138 | with open(from_path, 'rb') as src: |
| 139 | contents = src.read() |
| 140 | atomic_write(to_path, contents) |
| 141 | |
| 142 | |
| 143 | @enforce_types |
nothing calls this directly
no test coverage detected