MCPcopy Create free account
hub / github.com/cosdata/cosdata / validate_link

Method validate_link

org/src/viewer.rs:65–98  ·  view source on GitHub ↗
(&self, dir: &Path)

Source from the content-addressed store, hash-verified

63 }
64
65 fn validate_link(&self, dir: &Path) -> LinkValidation {
66 if self.is_absent() {
67 return LinkValidation {
68 is_valid: true,
69 reason: None,
70 };
71 }
72
73 let index_file = dir.join(format!("{}.index", self.file_id));
74
75 if !index_file.exists() {
76 return LinkValidation {
77 is_valid: false,
78 reason: Some(format!("Index file {:?} not found", index_file)),
79 };
80 }
81
82 let file_size = std::fs::metadata(&index_file).map(|m| m.len()).unwrap_or(0);
83
84 if (self.offset as u64) >= file_size {
85 return LinkValidation {
86 is_valid: false,
87 reason: Some(format!(
88 "Offset {} exceeds file size {}",
89 self.offset, file_size
90 )),
91 };
92 }
93
94 LinkValidation {
95 is_valid: true,
96 reason: None,
97 }
98 }
99}
100
101#[derive(Debug)]

Callers 2

read_neighborsFunction · 0.80
read_nodeFunction · 0.80

Calls 2

is_absentMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected