def copy_dir(src_dir, dst_dir, ignore=None, **kwargs):
    """Copy a directory recursively using `shutil.copytree`.

    Handles shutil.Error exceptions that happen even though all files were copied successfully.

    :param src_dir: The source directory. Can be a string or a `Path` object.
    :param dst_dir: The destination directory. Can be a string or a `Path` object.
    :param ignore: A callable that is used as `ignore` parameter to `shutil.copytree`.
    :param kwargs: Additional kwargs to pass to `shutil.copytree`.
    """
    try:
        shutil.copytree(src_dir, dst_dir, ignore=ignore, **kwargs)
    except shutil.Error as e:
        src_dir = Path(src_dir).resolve()
        dst_dir = Path(dst_dir).resolve()
        # Check if all files were copied successfully
        # only check files names so it is not foolproof
        not_copied = [
            member.relative_to(src_dir)
            for member in all_files(src_dir, ignore)
            if not (dst_dir / member.relative_to(src_dir)).exists()
        ]
        if not_copied:
            raise RuntimeError(f"Failed to copy {not_copied}") from e
        else:
            logger.warning(
                "Received shutil.Error '%s' but all required file names exist in destination directory. "
                "Assuming all files were copied successfully and continuing.",
                e,
            )
Copy a directory recursively using `shutil.copytree`.

    Handles shutil.Error exceptions that happen even though all files were copied successfully.

    :param src_dir: The source directory. Can be a string or a `Path` object.
    :param dst_dir: The destination directory. Can be a string or a `Path` object.
    :param ignore: A callable that is used as `ignore` parameter to `shutil.copytree`.
    :param kwargs: Additional kwargs to pass to `shutil.copytree`.
    
olive/common/utils.py