Mountain/ApplicationState/Internal/Persistence/MementoLoader/CreateCorruptedBackup.rs
1//! Timestamped corruption backup: write the failed-to-parse content
2//! to a `.json.corrupted.YYYYMMDD_HHMMSS` sibling so several
3//! recovery attempts in a row don't clobber each other. Pure
4//! side-effect; never fails the caller.
5
6use std::{fs, path::Path};
7
8use crate::dev_log;
9
10pub fn Fn(FilePath:&Path, Content:&str) {
11 let Timestamp = chrono::Utc::now().format("%Y%m%d_%H%M%S");
12
13 let BackupPath = FilePath.with_extension(format!("json.corrupted.{}", Timestamp));
14
15 if let Err(E) = fs::write(&BackupPath, Content) {
16 dev_log!(
17 "storage",
18 "error: [MementoLoader] Failed to create corrupted backup at '{}': {}",
19 BackupPath.display(),
20 E
21 );
22 } else {
23 dev_log!(
24 "storage",
25 "[MementoLoader] Created corrupted backup at: {}",
26 BackupPath.display()
27 );
28 }
29}