Skip to content

Commit 2d80247

Browse files
committed
fix: handle file path deletion for renamed files in embedding processor and status services
1 parent 8c2ffab commit 2d80247

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

internal/service/embedding_processor.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ func (ep *embeddingProcessService) uploadFilePathFailed(event *model.Event, uplo
367367
}
368368
delete(codebaseEmbeddingConfig.HashTree, filePath)
369369
delete(codebaseEmbeddingConfig.SyncFiles, filePath)
370+
if event.EventType == model.EventTypeRenameFile {
371+
delete(codebaseEmbeddingConfig.HashTree, event.SourceFilePath)
372+
delete(codebaseEmbeddingConfig.SyncFiles, event.SourceFilePath)
373+
}
370374
if utils.IsUnauthorizedError(uploadErr) {
371375
codebaseEmbeddingConfig.FailedFiles[filePath] = errs.ErrAuthenticationFailed
372376
} else if utils.IsTooManyRequestsError(uploadErr) {
@@ -423,12 +427,14 @@ func (ep *embeddingProcessService) CleanWorkspaceFilePath(ctx context.Context, f
423427
}
424428

425429
// 根据事件类型处理不同的文件路径
430+
filePath := event.SourceFilePath
426431
var filePaths []string
427432
switch event.EventType {
428433
case model.EventTypeAddFile, model.EventTypeModifyFile, model.EventTypeDeleteFile:
429434
filePaths = []string{event.SourceFilePath}
430435
case model.EventTypeRenameFile:
431436
filePaths = []string{event.SourceFilePath, event.TargetFilePath}
437+
filePath = event.TargetFilePath
432438
default:
433439
ep.logger.Warn("unsupported event type for cleaning filepath: %d", event.EventType)
434440
return nil
@@ -464,17 +470,13 @@ func (ep *embeddingProcessService) CleanWorkspaceFilePath(ctx context.Context, f
464470

465471
// 从SyncFiles中添加对应的文件路径
466472
if codebaseEmbeddingConfig.SyncFiles != nil {
467-
for _, filePath := range filePaths {
468-
if oldHash, exists := codebaseEmbeddingConfig.SyncFiles[filePath]; !exists || oldHash != fileStatus.Hash {
469-
codebaseEmbeddingConfig.SyncFiles[filePath] = fileStatus.Hash
470-
updated = true
471-
}
473+
if oldHash, exists := codebaseEmbeddingConfig.SyncFiles[filePath]; !exists || oldHash != fileStatus.Hash {
474+
codebaseEmbeddingConfig.SyncFiles[filePath] = fileStatus.Hash
475+
updated = true
472476
}
473477
} else {
474478
codebaseEmbeddingConfig.SyncFiles = make(map[string]string)
475-
for _, filePath := range filePaths {
476-
codebaseEmbeddingConfig.SyncFiles[filePath] = fileStatus.Hash
477-
}
479+
codebaseEmbeddingConfig.SyncFiles[filePath] = fileStatus.Hash
478480
updated = true
479481
}
480482

internal/service/embedding_status.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ func (sc *embeddingStatusService) buildFilePathFailed(event *model.Event) error
264264
codebaseEmbeddingConfig.SyncFiles = make(map[string]string)
265265
}
266266
delete(codebaseEmbeddingConfig.SyncFiles, filePath)
267+
if event.EventType == model.EventTypeRenameFile {
268+
delete(codebaseEmbeddingConfig.SyncFiles, event.SourceFilePath)
269+
}
267270
codebaseEmbeddingConfig.FailedFiles[filePath] = errs.ErrFileEmbeddingFailed
268271
// 保存 codebase embedding 配置
269272
err = sc.codebaseEmbeddingRepo.SaveCodebaseEmbeddingConfig(codebaseEmbeddingConfig)

0 commit comments

Comments
 (0)