Skip to main content

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

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