(&self, dir: &Path)
| 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)] |
no test coverage detected