+46
-7
src/reftable/fsck.rs
+46
-7
src/reftable/fsck.rs
···
1
1
use crate::reftable::reftable_table::ReftableTable;
2
2
3
+
#[derive(Debug)]
3
4
pub enum ReftableFsckError {
4
-
TableName,
5
+
TableName(String),
5
6
MaxValue,
6
7
}
7
8
9
+
impl std::fmt::Display for ReftableFsckError {
10
+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
11
+
match self {
12
+
ReftableFsckError::TableName(name) => {
13
+
write!(f, "Invalid reftable table name: {}", name)
14
+
}
15
+
ReftableFsckError::MaxValue => write!(f, "Maximum value exceeded"),
16
+
}
17
+
}
18
+
}
19
+
20
+
impl std::error::Error for ReftableFsckError {}
21
+
8
22
pub struct ReftableFsckInfo {
9
23
pub msg: String,
10
24
pub path: String,
···
12
26
}
13
27
14
28
pub fn table_has_valid_name(name: &str) -> bool {
15
-
todo!()
29
+
return name
30
+
.split('-')
31
+
.map(|s| i64::from_str_radix(s, 16).is_ok())
32
+
.reduce(|a, b| a && b)
33
+
.unwrap_or(false)
34
+
&& (name.ends_with(".ref") || name.ends_with(".log"));
16
35
}
17
36
18
-
pub fn table_check_name(table: &ReftableTable) -> Result<(), String> {
19
-
todo!()
37
+
pub fn table_check_name(table: &ReftableTable) -> Result<(), ReftableFsckError> {
38
+
if !table_has_valid_name(&table.name) {
39
+
Err(ReftableFsckError::TableName(table.name.clone()))
40
+
} else {
41
+
Ok(())
42
+
}
20
43
}
21
44
22
-
pub fn table_checks(table: &ReftableTable) -> Result<(), String> {
23
-
todo!()
45
+
pub fn table_checks<T>(table: &ReftableTable) -> Result<(), String>
46
+
where
47
+
T: FnMut(&ReftableFsckInfo) + Clone,
48
+
{
49
+
let table_check_fns = vec![table_check_name];
50
+
51
+
for check_fn in table_check_fns {
52
+
match check_fn(table) {
53
+
Ok(()) => {}
54
+
Err(err) => {
55
+
return Err(err.to_string());
56
+
}
57
+
}
58
+
}
59
+
Ok(())
24
60
}
25
61
26
62
pub fn reftable_fsck_check(stack: &ReftableStack) -> Result<(), String> {
27
-
todo!()
63
+
for table in stack.tables {
64
+
table_checks(table)?;
65
+
}
66
+
Ok(())
28
67
}
History
1 round
1 comment
thecoded.prof
submitted
#0
1 commit
expand
collapse
feat: convert fsck.rs
expand 1 comment
closed without merging
manually merged - I wonder if our PDS is having issues or something?