import pathlib
from typing import Literal
import hashlib


def _file_ok(path: pathlib.Path, md5sum: str, open_mode: Literal["r", "rb"] = "rb") -> bool:
    """Checks if `path` exists and has the desired MD5 checksum."""
    if not path.is_file():
        return False

    with open(path, open_mode) as f:
        checksum = hashlib.md5(f.read()).hexdigest()

    return checksum == md5sum