fix: 修复资源泄漏和空文件上传问题
All checks were successful
构建上传工具 / build-tool (push) Successful in 2m9s

This commit is contained in:
2025-10-17 22:34:25 +08:00
parent 2092fae819
commit ed220996a7
2 changed files with 12 additions and 2 deletions

13
main.go
View File

@@ -113,7 +113,7 @@ func main() {
AddLog(s)
isRun = true
go StartLooking(ctx, selectedDirLabel.Text)
go StartLooking(ctx, config.APPConfig.LookingPath)
})
stopBtn := widget.NewButton("停止运行", func() {
@@ -213,7 +213,7 @@ func main() {
AddLog(s)
isRun = true
go StartLooking(ctx, selectedDirLabel.Text)
go StartLooking(ctx, config.APPConfig.LookingPath)
}()
myWindow.SetContent(splitContainer)
@@ -247,6 +247,7 @@ type Task struct {
}
func StartLooking(ctx context.Context, lookingPath string) {
AddLog("正在运行上传程序")
t := time.NewTicker(time.Minute)
defer t.Stop()
@@ -269,6 +270,7 @@ func StartLooking(ctx context.Context, lookingPath string) {
//统计文件行数
fileLines := make(map[string]int)
AddLog(fmt.Sprintf("正在统计 %v 个文件行数", len(files)))
isAllEmpty := true
for _, filePath := range files {
select {
case <-ctx.Done():
@@ -290,9 +292,16 @@ func StartLooking(ctx context.Context, lookingPath string) {
continue
}
fileLines[filepath.Base(filePath)] = lineCount
if lineCount != 0 {
isAllEmpty = false
}
AddLog(fmt.Sprintf("%s 文件行数:%v", filepath.Base(filePath), lineCount))
}
}
if isAllEmpty {
AddLog("所有文件都为空,不进行上传")
return
}
//添加任务
var tasks []Task