def _copy_allowed_file(filepath: Path, dst_directory: Path):
    """
    Copies files from allowlist to a directory, overriding existing
    files or directories if any.
    """
    if filepath.name not in _ALLOWLIST_PATHS:
        return

    dst = dst_directory / filepath.name
    if dst.is_dir():
        shutil.rmtree(str(dst))
    elif dst.is_file():
        dst.unlink()
    if filepath.is_dir():
        shutil.copytree(filepath, dst)
    elif filepath.is_file():
        if filepath.name in ["best.th", "weights.th"]:
            dst = dst_directory / "weights.th"
        shutil.copy(str(filepath), str(dst))
Copies files from allowlist to a directory, overriding existing
files or directories if any.
allennlp/common/push_to_hf.py