Skip to content

Commit 11b590f

Browse files
committed
🐛 修复删除操作的文件存在性验证问题
- 移除删除标签、关系、注释时的文件存在性检查 - 允许清理已删除文件的孤儿数据记录 - 修改MCP接口层和管理器层的删除逻辑 - 提升数据清理的灵活性和实用性
1 parent 964542f commit 11b590f

File tree

6 files changed

+19
-34
lines changed

6 files changed

+19
-34
lines changed

.cunzhi-memory/context.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
- 已为CodeNexus项目建立完整代码关系体系:17个文件100%标记和注释,31个依赖关系,37个多维度标签,支持智能查询、关系分析、架构导航等功能
55
- 已为CodeNexus查询引擎实现完整操作符支持:NOT、OR、通配符、复合查询,支持复杂表达式如"(type:manager OR type:adapter) AND NOT module:core",并更新README文档说明新功能
66
- 为CodeNexus项目创建了完整的自动发布系统,参考cunzhi项目的GitHub Actions配置。包含:1) .github/workflows/release.yml - 多平台构建和自动发布工作流;2) cliff.toml - git-cliff配置文件用于生成changelog;3) scripts/release.ps1和release.sh - Windows和Linux/macOS发布脚本;4) docs/RELEASE_GUIDE.md - 详细的发布指南文档。系统支持版本一致性检查、自动changelog生成、多平台二进制构建、GitHub Release创建等功能。
7+
- 修复了CodeNexus项目中删除操作的文件存在性验证问题。删除标签、删除关系、删除注释操作不再验证文件是否存在,因为文件可能已被删除但数据库中还有相关记录需要清理。修改了src/mcp/adapter.rs中的remove_file_tags和remove_file_relation方法,以及src/managers/tag_manager.rs、src/managers/relation_manager.rs、src/managers/comment_manager.rs中的相应删除方法,移除了不必要的文件存在性检查。

.cunzhi-memory/metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"project_path": "\\\\?\\E:\\Projects\\MyProjects\\code_nexus",
3-
"last_organized": "2025-07-08T08:47:34.946942400Z",
4-
"total_entries": 6,
3+
"last_organized": "2025-07-08T11:22:08.414505100Z",
4+
"total_entries": 7,
55
"version": "1.0.0"
66
}

src/managers/comment_manager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl CommentManager {
112112

113113
/// 删除文件注释
114114
pub async fn delete_comment(&mut self, file_path: &str) -> Result<()> {
115+
// 对于删除操作,不验证文件是否存在,因为文件可能已被删除但数据库中还有记录
115116
if let Some(_) = self.file_comments.remove(file_path) {
116117
self.save_to_storage().await?;
117118
info!("删除了文件 {} 的注释", file_path);

src/managers/relation_manager.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,9 @@ impl RelationManager {
112112

113113
/// 移除文件关联关系
114114
pub async fn remove_relation(&mut self,
115-
absolute_from_file: &Path, relative_from_file: &str,
116-
absolute_to_file: &Path, relative_to_file: &str) -> Result<()> {
117-
// 验证文件路径
118-
self.validate_file_path(absolute_from_file)?;
119-
self.validate_file_path(absolute_to_file)?;
115+
_absolute_from_file: &Path, relative_from_file: &str,
116+
_absolute_to_file: &Path, relative_to_file: &str) -> Result<()> {
117+
// 对于删除操作,不验证文件是否存在,因为文件可能已被删除但数据库中还有记录
120118

121119
// 检查关联关系是否存在(使用相对路径)
122120
let relations = self.file_relations.get_mut(relative_from_file)

src/managers/tag_manager.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ impl TagManager {
148148
}
149149

150150
/// 移除文件标签
151-
pub async fn remove_tags(&mut self, absolute_file_path: &Path, relative_file_path: &str, tags: Vec<String>) -> Result<()> {
152-
// 验证文件路径(使用绝对路径)
153-
self.validate_file_path(absolute_file_path)?;
151+
pub async fn remove_tags(&mut self, _absolute_file_path: &Path, relative_file_path: &str, tags: Vec<String>) -> Result<()> {
152+
// 对于删除操作,不验证文件是否存在,因为文件可能已被删除但数据库中还有记录
154153

155154
// 先检查文件是否存在标签(使用相对路径)
156155
if !self.file_tags.contains_key(relative_file_path) {

src/mcp/adapter.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl CodeNexusServer {
294294
debug_log_with_project!(&params.project_path, "移除文件标签 - 项目路径: {}, 文件路径: {}, 标签: {:?}",
295295
params.project_path, params.file_path, params.tags);
296296

297-
// 验证路径并获取项目管理器
297+
// 验证项目路径
298298
let validated_path = match validate_project_path(&params.project_path) {
299299
Ok(path) => {
300300
debug_log_with_project!(&params.project_path, "项目路径验证成功: {}", path.display());
@@ -303,13 +303,9 @@ impl CodeNexusServer {
303303
Err(e) => return format!("项目路径验证失败: {}", e),
304304
};
305305

306-
let full_file_path = match validate_file_path(&validated_path, &params.file_path) {
307-
Ok(path) => {
308-
debug_log_with_project!(&params.project_path, "文件路径验证成功: {}", path.display());
309-
path
310-
},
311-
Err(e) => return format!("文件路径验证失败: {}", e),
312-
};
306+
// 对于删除操作,不验证文件是否存在,因为文件可能已被删除但数据库中还有记录
307+
let full_file_path = validated_path.join(&params.file_path);
308+
debug_log_with_project!(&params.project_path, "构建文件路径: {}", full_file_path.display());
313309

314310
let normalized_path = match normalize_file_path(&validated_path, &full_file_path) {
315311
Ok(path) => {
@@ -590,7 +586,7 @@ impl CodeNexusServer {
590586
debug_log_with_project!(&params.project_path, "移除文件关联关系 - 项目路径: {}, 源文件: {}, 目标文件: {}",
591587
params.project_path, params.from_file, params.to_file);
592588

593-
// 验证路径
589+
// 验证项目路径
594590
let validated_path = match validate_project_path(&params.project_path) {
595591
Ok(path) => {
596592
debug_log_with_project!(&params.project_path, "项目路径验证成功: {}", path.display());
@@ -599,21 +595,11 @@ impl CodeNexusServer {
599595
Err(e) => return format!("项目路径验证失败: {}", e),
600596
};
601597

602-
let from_file_path = match validate_file_path(&validated_path, &params.from_file) {
603-
Ok(path) => {
604-
debug_log_with_project!(&params.project_path, "源文件路径验证成功: {}", path.display());
605-
path
606-
},
607-
Err(e) => return format!("源文件路径验证失败: {}", e),
608-
};
609-
610-
let to_file_path = match validate_file_path(&validated_path, &params.to_file) {
611-
Ok(path) => {
612-
debug_log_with_project!(&params.project_path, "目标文件路径验证成功: {}", path.display());
613-
path
614-
},
615-
Err(e) => return format!("目标文件路径验证失败: {}", e),
616-
};
598+
// 对于删除操作,不验证文件是否存在,因为文件可能已被删除但数据库中还有记录
599+
let from_file_path = validated_path.join(&params.from_file);
600+
let to_file_path = validated_path.join(&params.to_file);
601+
debug_log_with_project!(&params.project_path, "构建源文件路径: {}", from_file_path.display());
602+
debug_log_with_project!(&params.project_path, "构建目标文件路径: {}", to_file_path.display());
617603

618604
let normalized_from = match normalize_file_path(&validated_path, &from_file_path) {
619605
Ok(path) => {

0 commit comments

Comments
 (0)