Skip to main content

prepare

Function prepare 

Source
pub fn prepare(
    cfg: &Config,
    on_progress: impl FnMut(Progress) -> ControlFlow<()>,
) -> Result<(), Error>
Expand description

Make every model the config names present and verified.

Blocking, like everything else here: an async caller must run this on tokio::task::spawn_blocking or its equivalent. On a runtime thread it panics in a debug build and silently holds a worker for the whole transfer in a release one.

Downloads what is missing, resumes what was interrupted, and checks size then SHA-256 against the crate::ModelSpec before reporting a file ready. Safe to call repeatedly; a verified file is left alone.

A file that is present but does not match its spec is fetched again, which is what settles a mismatch of bytes. A file that cannot be read is reported instead: nothing says a fetch would help it.

Models are prepared concurrently, one thread each, so the pair costs the slower of the two rather than their sum. on_progress is still called from a single thread and one event at a time, but events from the two now interleave: a caller keeping per-transfer state must key it on Progress’s file.

Hashing is skipped for a file that has not changed since it was last verified, when Config::digest_cache_dir names a place to keep that record: the check becomes the stat it already needs. Without that directory every call re-hashes each file end to end, measured here at 0.55 s/GiB in release and 4.2 s/GiB unoptimised - the second reads as a hang rather than as the profile. sha2 0.11, which this tree has pinned since the sweep that moved it, is about four times faster than the 0.10 before it.