Git fork
fork

Configure Feed

Select the types of activity you want to include in your feed.

at reftables-rust 67 lines 1.7 kB view raw
1use crate::reftable::reftable_table::ReftableTable; 2 3#[derive(Debug)] 4pub enum ReftableFsckError { 5 TableName(String), 6 MaxValue, 7} 8 9impl 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 20impl std::error::Error for ReftableFsckError {} 21 22pub struct ReftableFsckInfo { 23 pub msg: String, 24 pub path: String, 25 pub error: ReftableFsckError, 26} 27 28pub 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 37pub 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 45pub fn table_checks<T>(table: &ReftableTable) -> Result<(), String> 46where 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 62pub fn reftable_fsck_check(stack: &ReftableStack) -> Result<(), String> { 63 for table in stack.tables { 64 table_checks(table)?; 65 } 66 Ok(()) 67}