#![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(path: &Path) -> Result { 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> = 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;