fix(uploader): 修复上传进度初始化逻辑
构建上传工具 / build-tool (push) Successful in 1m1s

- 在处理文件前先清除之前的进度记录
- 将循环变量名从 k, v 更改为 fileName, lines 提高可读性
- 移动进度初始化位置确保每个文件都有正确的进度跟踪
- 删除重复的进度清除操作避免潜在的数据丢失问题
This commit is contained in:
2026-04-28 01:35:16 +08:00
parent 75de353af6
commit 602c4c8546
2 changed files with 7 additions and 5 deletions
+4 -4
View File
@@ -118,7 +118,6 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
fileLines[filepath.Base(filePath)] = lineCount
isAllEmpty = false
AddLog(logChan, fmt.Sprintf("%s 文件行数:%v", filepath.Base(filePath), lineCount))
progress.Store(filepath.Base(filePath), Progress{FileName: filepath.Base(filePath), Total: lineCount, Uploaded: 0, Percentage: 0})
}
}
if isAllEmpty {
@@ -126,10 +125,12 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
return
}
progress.Clear()
//添加文件上传任务参数(文件路径,文件行数)
var tasks []Task
for k, v := range fileLines {
tasks = append(tasks, Task{FilePath: path + "/" + k, FileLines: v})
for fileName, lines := range fileLines {
tasks = append(tasks, Task{FilePath: path + "/" + fileName, FileLines: lines})
progress.Store(fileName, Progress{FileName: fileName, Total: lines, Uploaded: 0, Percentage: 0})
}
// 使用 errgroup 控制同时处理的文件数,并开始上传文件任务
@@ -178,7 +179,6 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
}
AddLog(logChan, fmt.Sprintf("上传完成,耗时:%s", time.Since(start).String()))
progress.Clear()
}
}