Skip to main content

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

1#![allow(non_snake_case)]
2
3//! Timestamped corruption backup: write the failed-to-parse content
4//! to a `.json.corrupted.YYYYMMDD_HHMMSS` sibling so several
5//! recovery attempts in a row don't clobber each other. Pure
6//! side-effect; never fails the caller.
7
8use std::{fs, path::Path};
9
10use crate::dev_log;
11
12pub fn Fn(FilePath:&Path, Content:&str) {
13	let Timestamp = chrono::Utc::now().format("%Y%m%d_%H%M%S");
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}