Skip to main content

write_cached

Function write_cached 

Source
fn write_cached(
    file: &WeightFile,
    bytes: &[u8],
) -> Result<PathBuf, DownloadError>
Expand description

Write bytes into the cache as file, atomically: a temp file unique to this writer, then a rename over the final name.

The temp name must be unique per writer, not just per file. Several threads or processes can fetch the same weights at once (a test binary runs its tests in parallel; CI jobs share a cache), and with one shared <name>.part a second writer’s File::create truncated the first writer’s temp file mid-write: the first then renamed a partial model into place (“model proto does not contain a graph”) and the second’s rename found no temp file (“No such file or directory”). With a unique temp file each rename installs a complete, verified file; the last one wins, and all of them hold the same bytes.