Skip to main content

Mountain/ApplicationState/Internal/Persistence/MementoLoader/
CreateCorruptedBackup.rs

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