a789495a98
FreeBSD Smoke / FreeBSD Smoke (x86_64) (push) Has been cancelled
CI / Quality Guardrails (push) Has been cancelled
CI / Build & Test (macos-latest) (push) Has been cancelled
CI / Build & Test (ubuntu-latest) (push) Has been cancelled
CI / Build & Test (windows-latest) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / PowerShell Syntax (push) Has been cancelled
CI / Windows Cross-Target Check (Linux) (push) Has been cancelled
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
#![cfg_attr(test, allow(clippy::items_after_test_module))]
|
|
|
|
pub use jcode_storage::*;
|
|
|
|
use anyhow::Result;
|
|
use serde::de::DeserializeOwned;
|
|
use std::path::Path;
|
|
|
|
pub fn read_json<T: DeserializeOwned>(path: &Path) -> Result<T> {
|
|
jcode_storage::read_json_with_recovery_handler(path, |event| match event {
|
|
jcode_storage::StorageRecoveryEvent::CorruptPrimary { path, error } => {
|
|
crate::logging::warn(&format!(
|
|
"Corrupt JSON at {}, trying backup: {}",
|
|
path.display(),
|
|
error
|
|
));
|
|
}
|
|
jcode_storage::StorageRecoveryEvent::RecoveredFromBackup { backup_path } => {
|
|
crate::logging::info(&format!("Recovered from backup: {}", backup_path.display()));
|
|
}
|
|
})
|
|
}
|
|
|
|
#[cfg(any(test, feature = "test-support"))]
|
|
use std::sync::{Mutex, MutexGuard, OnceLock};
|
|
|
|
#[cfg(any(test, feature = "test-support"))]
|
|
pub fn test_env_lock() -> &'static Mutex<()> {
|
|
static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
|
|
ENV_LOCK.get_or_init(|| Mutex::new(()))
|
|
}
|
|
|
|
#[cfg(any(test, feature = "test-support"))]
|
|
pub fn lock_test_env() -> MutexGuard<'static, ()> {
|
|
test_env_lock()
|
|
.lock()
|
|
.unwrap_or_else(|poisoned| poisoned.into_inner())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|