fn write_stash()

in rust-create-cascade/src/main.rs [641:677]


fn write_stash(
    output_stash_file: &Path,
    delta_dir: &Path,
    reason_set: ReasonSet,
    statsd_client: Option<&statsd::Client>,
) {
    let delta_files = Path::read_dir(delta_dir).unwrap();
    let delta_issuers: Vec<OsString> = delta_files
        .filter_map(|x| x.ok())
        .map(|x| x.file_name())
        .collect();

    let mut stash_bytes = vec![];
    for issuer in delta_issuers {
        let issuer_bytes = decode_issuer(issuer.to_str().expect("non-unicode issuer string"));
        let delta_file = delta_dir.join(&issuer);
        let delta_serial_set: HashSet<Serial> =
            RevokedSerialAndReasonIterator::new(&delta_file, reason_set).into();
        if !delta_serial_set.is_empty() {
            stash_bytes.extend((delta_serial_set.len() as u32).to_le_bytes());
            stash_bytes.push(issuer_bytes.len() as u8);
            stash_bytes.extend_from_slice(&issuer_bytes);
            for serial_str in delta_serial_set {
                let serial = decode_serial(&serial_str);
                stash_bytes.push(serial.len() as u8);
                stash_bytes.extend_from_slice(serial.as_ref());
            }
        }
    }

    info!("Stash is {} bytes", stash_bytes.len());
    std::fs::write(output_stash_file, &stash_bytes).expect("can't write stash file");

    if let Some(client) = statsd_client {
        client.gauge("stash_size", stash_bytes.len() as f64);
    }
}