def hardlink_copy_file(src, dst, *, follow_symlinks=True):
    """Copy a file using hardlink if possible, otherwise use shutil.copy2.

    Similar to shutil.copy2, if the destination is a directory, the file will be copied into the directory with the
    same name.
    If the destination file exists, it will be overwritten.
    """
    src = Path(src).resolve()  # NOTE: This call resolves any symlinks
    dst = Path(dst).resolve()

    if not src.exists():
        raise ValueError("Input source doesn't exist.", src)
    elif not src.is_file():
        raise ValueError("Input source is expected to be a file.", src)

    if dst.is_dir():
        dst = Path(dst) / src.name

    if dst.exists():
        logger.debug("Destination %s already exists. Removing.", dst)
        dst.unlink()

    try:
        os.link(src, dst, follow_symlinks=follow_symlinks)
    except OSError as e:
        # for instance, hardlinking across filesystems is not supported
        logger.debug("Linking failed with %s. Copying.", e)
        shutil.copy2(src, dst, follow_symlinks=follow_symlinks)
Copy a file using hardlink if possible, otherwise use shutil.copy2.

    Similar to shutil.copy2, if the destination is a directory, the file will be copied into the directory with the
    same name.
    If the destination file exists, it will be overwritten.
    
olive/common/utils.py