1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use crate::{LockboxEntry, RecoveryReportOptions};
/// Summary produced by lockbox recovery and salvage scans.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RecoveryReport {
/// Intact file entries discovered by the scan.
pub intact_files: Vec<LockboxEntry>,
/// Total number of intact files, including entries omitted from
/// `intact_files` by reporting limits.
pub intact_file_count: usize,
/// Number of file records that were only partially recoverable.
pub partial_files: usize,
/// Paths and failure categories for entries that could not be read completely.
/// Paths whose metadata could not be recovered are not invented here.
pub partial_file_details: Vec<(String, String)>,
/// Number of corrupt records encountered.
pub corrupt_records: usize,
/// Whether the latest TOC could be read.
pub toc_recovered: bool,
/// Whether variable metadata was recovered from the latest commit root.
pub variables_recovered: bool,
/// Number of variable values recovered.
pub variable_count: usize,
/// Whether form metadata was recovered from the latest commit root.
pub forms_recovered: bool,
/// Number of latest form definitions recovered.
pub form_definition_count: usize,
/// Number of form records recovered.
pub form_record_count: usize,
}
impl RecoveryReport {
/// Render a human-readable report.
pub fn render(&self, options: &RecoveryReportOptions) -> String {
let mut out = String::new();
out.push_str("Recovery report\n\n");
out.push_str("Summary:\n");
out.push_str(&format!(" Intact files: {}\n", self.intact_file_count));
out.push_str(&format!(" Partial files: {}\n", self.partial_files));
out.push_str(&format!(" Corrupt records: {}\n", self.corrupt_records));
out.push_str(&format!(
" Latest TOC: {}\n",
if self.toc_recovered {
"intact"
} else {
"not used or damaged"
}
));
out.push_str(&format!(
" Variables: {} ({})\n",
self.variable_count,
if self.variables_recovered {
"recovered"
} else {
"not recovered"
}
));
out.push_str(&format!(
" Forms: {} definitions, {} items ({})\n",
self.form_definition_count,
self.form_record_count,
if self.forms_recovered {
"recovered"
} else {
"not recovered"
}
));
if options.verbose {
out.push_str("\nIntact:\n");
let limit = options
.max_intact_entries
.unwrap_or(self.intact_files.len());
for entry in self.intact_files.iter().take(limit) {
out.push_str(&format!(" {}\n", entry.path));
}
if self.intact_files.len() > limit {
out.push_str(&format!(
" ... {} more intact files omitted\n",
self.intact_files.len() - limit
));
}
}
if self.partial_files > 0 || self.corrupt_records > 0 {
out.push_str("\nAttention required:\n");
if self.partial_files > 0 {
out.push_str(&format!(
" Partial files detected: {}\n",
self.partial_files
));
for (path, reason) in &self.partial_file_details {
out.push_str(&format!(" {path}: {reason}\n"));
}
let unidentified = self
.partial_files
.saturating_sub(self.partial_file_details.len());
if unidentified > 0 {
out.push_str(&format!(
" Partial files without recovered paths: {unidentified}\n"
));
}
}
if self.corrupt_records > 0 {
out.push_str(&format!(
" Corrupt records detected: {}\n",
self.corrupt_records
));
}
}
out
}
}