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
15	let BackupPath = FilePath.with_extension(format!("json.corrupted.{}", Timestamp));
16
17	if let Err(E) = fs::write(&BackupPath, Content) {
18		dev_log!(
19			"storage",
20			"error: [MementoLoader] Failed to create corrupted backup at '{}': {}",
21			BackupPath.display(),
22			E
23		);
24	} else {
25		dev_log!(
26			"storage",
27			"[MementoLoader] Created corrupted backup at: {}",
28			BackupPath.display()
29		);
30	}
31}