tangled
alpha
login
or
join now
freshlybakedca.ke
/
git
5
fork
atom
Git fork
5
fork
atom
overview
issues
pulls
2
pipelines
feat: convert fsck.rs
thecoded.prof
2 weeks ago
7c007fa9
2cdb7a38
verified
This commit was signed with the committer's
known signature
.
thecoded.prof
SSH Key Fingerprint:
SHA256:ePn0u8NlJyz3J4Zl9MHOYW3f4XKoi5K1I4j53bwpG0U=
+46
-7
1 changed file
expand all
collapse all
unified
split
src
reftable
fsck.rs
+46
-7
src/reftable/fsck.rs
···
1
1
use crate::reftable::reftable_table::ReftableTable;
2
2
3
3
+
#[derive(Debug)]
3
4
pub enum ReftableFsckError {
4
4
-
TableName,
5
5
+
TableName(String),
5
6
MaxValue,
6
7
}
7
8
9
9
+
impl std::fmt::Display for ReftableFsckError {
10
10
+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
11
11
+
match self {
12
12
+
ReftableFsckError::TableName(name) => {
13
13
+
write!(f, "Invalid reftable table name: {}", name)
14
14
+
}
15
15
+
ReftableFsckError::MaxValue => write!(f, "Maximum value exceeded"),
16
16
+
}
17
17
+
}
18
18
+
}
19
19
+
20
20
+
impl std::error::Error for ReftableFsckError {}
21
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
15
-
todo!()
29
29
+
return name
30
30
+
.split('-')
31
31
+
.map(|s| i64::from_str_radix(s, 16).is_ok())
32
32
+
.reduce(|a, b| a && b)
33
33
+
.unwrap_or(false)
34
34
+
&& (name.ends_with(".ref") || name.ends_with(".log"));
16
35
}
17
36
18
18
-
pub fn table_check_name(table: &ReftableTable) -> Result<(), String> {
19
19
-
todo!()
37
37
+
pub fn table_check_name(table: &ReftableTable) -> Result<(), ReftableFsckError> {
38
38
+
if !table_has_valid_name(&table.name) {
39
39
+
Err(ReftableFsckError::TableName(table.name.clone()))
40
40
+
} else {
41
41
+
Ok(())
42
42
+
}
20
43
}
21
44
22
22
-
pub fn table_checks(table: &ReftableTable) -> Result<(), String> {
23
23
-
todo!()
45
45
+
pub fn table_checks<T>(table: &ReftableTable) -> Result<(), String>
46
46
+
where
47
47
+
T: FnMut(&ReftableFsckInfo) + Clone,
48
48
+
{
49
49
+
let table_check_fns = vec![table_check_name];
50
50
+
51
51
+
for check_fn in table_check_fns {
52
52
+
match check_fn(table) {
53
53
+
Ok(()) => {}
54
54
+
Err(err) => {
55
55
+
return Err(err.to_string());
56
56
+
}
57
57
+
}
58
58
+
}
59
59
+
Ok(())
24
60
}
25
61
26
62
pub fn reftable_fsck_check(stack: &ReftableStack) -> Result<(), String> {
27
27
-
todo!()
63
63
+
for table in stack.tables {
64
64
+
table_checks(table)?;
65
65
+
}
66
66
+
Ok(())
28
67
}