Skip to main content

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

1#![allow(non_snake_case)]
2
3//! Side-channel: write the corrupted memento payload to a `.backup`
4//! sibling so a human can inspect the original. Failure to write the
5//! backup is logged but doesn't propagate - the load path stays
6//! best-effort.
7
8use std::{fs, path::Path};
9
10use crate::dev_log;
11
12pub fn Fn(FilePath:&Path, CorruptedContent:&str) {
13	let BackupPath = FilePath.with_extension("json.backup");
14
15	match fs::write(&BackupPath, CorruptedContent) {
16		Ok(()) => {
17			dev_log!(
18				"storage",
19				"warn: [MementoLoader] Created backup of corrupted memento at: {}",
20				BackupPath.display()
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}