Git fork

feat: convert fsck.rs #5

closed opened by thecoded.prof targeting reftables-rust from private/coded/push-lpqqurlxxkwn
Labels

None yet.

requested-reviewers

None yet.

approved

None yet.

tested-working

None yet.

rejected

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:t4ifz7bz4cnukxryiqnbgxxr/sh.tangled.repo.pull/3mfnso2thee22
+46 -7
Diff #0
+46 -7
src/reftable/fsck.rs
··· 1 use crate::reftable::reftable_table::ReftableTable; 2 3 pub enum ReftableFsckError { 4 - TableName, 5 MaxValue, 6 } 7 8 pub struct ReftableFsckInfo { 9 pub msg: String, 10 pub path: String, ··· 12 } 13 14 pub fn table_has_valid_name(name: &str) -> bool { 15 - todo!() 16 } 17 18 - pub fn table_check_name(table: &ReftableTable) -> Result<(), String> { 19 - todo!() 20 } 21 22 - pub fn table_checks(table: &ReftableTable) -> Result<(), String> { 23 - todo!() 24 } 25 26 pub fn reftable_fsck_check(stack: &ReftableStack) -> Result<(), String> { 27 - todo!() 28 }
··· 1 use crate::reftable::reftable_table::ReftableTable; 2 3 + #[derive(Debug)] 4 pub enum ReftableFsckError { 5 + TableName(String), 6 MaxValue, 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 + 22 pub struct ReftableFsckInfo { 23 pub msg: String, 24 pub path: String, ··· 26 } 27 28 pub fn table_has_valid_name(name: &str) -> bool { 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")); 35 } 36 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 + } 43 } 44 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(()) 60 } 61 62 pub fn reftable_fsck_check(stack: &ReftableStack) -> Result<(), String> { 63 + for table in stack.tables { 64 + table_checks(table)?; 65 + } 66 + Ok(()) 67 }

History

1 round 1 comment
sign up or login to add to the discussion
thecoded.prof submitted #0
1 commit
expand
feat: convert fsck.rs
expand 1 comment

manually merged - I wonder if our PDS is having issues or something?

closed without merging