use crate::spec::types::ParityFailure;
use std::fs;
use std::io::{self, Write};
use std::path::PathBuf;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{SystemTime, UNIX_EPOCH};
#[cfg(loom)]
use loom::sync::Mutex as LoomMutex;
use super::hex::*;
#[inline]
pub fn save(failure: &ParityFailure) -> io::Result<PathBuf> {
#[cfg(loom)]
{
let mut store = LOOM_STORE.lock().unwrap();
store.push(failure.clone());
return Ok(PathBuf::from("loom-mem"));
}
#[cfg(not(loom))]
{
let dir = versioned_regression_dir(&failure.op_id, failure.spec_version);
fs::create_dir_all(&dir)?;
let bytes = serialize_failure(failure)?;
let name = format!("{}.json", sha256_hex(&failure.input));
let path = dir.join(name);
atomic_write_new(&path, &bytes)?;
Ok(path)
}
}