Skip to main content

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

1
2//! Side-channel: write the corrupted memento payload to a `.backup`
3//! sibling so a human can inspect the original. Failure to write the
4//! backup is logged but doesn't propagate - the load path stays
5//! best-effort.
6
7use std::{fs, path::Path};
8
9use crate::dev_log;
10
11pub fn Fn(FilePath:&Path, CorruptedContent:&str) {
12	let BackupPath = FilePath.with_extension("json.backup");
13
14	match fs::write(&BackupPath, CorruptedContent) {
15		Ok(()) => {
16			dev_log!(
17				"storage",
18				"warn: [MementoLoader] Created backup of corrupted memento at: {}",
19				BackupPath.display()
20			)
21		},
22
23		Err(E) => {
24			dev_log!(
25				"storage",
26				"error: [MementoLoader] Failed to create backup of corrupted memento at '{}': {}",
27				BackupPath.display(),
28				E
29			)
30		},
31	}
32}