更新单个文件
(
&mut self,
file_path: &PathBuf,
entity_graph: &mut EntityGraph,
call_graph: &mut PetCodeGraph,
)
| 61 | |
| 62 | /// 更新单个文件 |
| 63 | pub fn refresh_file( |
| 64 | &mut self, |
| 65 | file_path: &PathBuf, |
| 66 | entity_graph: &mut EntityGraph, |
| 67 | call_graph: &mut PetCodeGraph, |
| 68 | ) -> Result<(), String> { |
| 69 | info!("Refreshing file: {}", file_path.display()); |
| 70 | |
| 71 | // 检查文件是否存在 |
| 72 | if !file_path.exists() { |
| 73 | // 文件被删除,清理相关索引 |
| 74 | self._remove_file_entities(file_path, entity_graph, call_graph); |
| 75 | return Ok(()); |
| 76 | } |
| 77 | |
| 78 | // 计算当前MD5 |
| 79 | let current_md5 = self.compute_file_md5(file_path) |
| 80 | .map_err(|e| format!("Failed to compute MD5 for {}: {}", file_path.display(), e))?; |
| 81 | |
| 82 | // 检查是否需要更新 |
| 83 | if let Some(metadata) = self.file_metadata.get(file_path) { |
| 84 | if metadata.md5 == current_md5 { |
| 85 | debug!("File {} unchanged, skipping", file_path.display()); |
| 86 | return Ok(()); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // 文件需要更新,执行增量更新 |
| 91 | self._update_file(file_path, ¤t_md5, entity_graph, call_graph)?; |
| 92 | |
| 93 | Ok(()) |
| 94 | } |
| 95 | |
| 96 | /// 更新文件元数据 |
| 97 | fn _update_file( |
nothing calls this directly
no test coverage detected