fn truncate_guest_pool_file()

in src/kvp.rs [454:483]


fn truncate_guest_pool_file(kvp_file: &Path) -> Result<(), anyhow::Error> {
    let boot_time = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs()
        - get_uptime().as_secs();

    match kvp_file.metadata() {
        Ok(metadata) => {
            if metadata.mtime() < boot_time as i64 {
                OpenOptions::new()
                    .write(true)
                    .truncate(true)
                    .open(kvp_file)?;
                println!("Truncated the KVP file due to stale data.");
            } else {
                println!(
                    "File has been truncated since boot, no action taken."
                );
            }
        }
        Err(ref e) if e.kind() == ErrorKind::NotFound => {
            println!("File not found: {:?}", kvp_file);
            return Ok(());
        }
        Err(e) => {
            return Err(anyhow::Error::from(e)
                .context("Failed to access file metadata"));
        }
    }

    Ok(())
}