fix: EXIF解析越界与转正丢文件、.psb归类、日志接管panic恢复

This commit is contained in:
2025-05-25 21:01:16 +08:00
parent a2cded251a
commit cf8d991974
3 changed files with 29 additions and 8 deletions
+13
View File
@@ -17,6 +17,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"runtime/debug"
"strings"
"sync"
"time"
@@ -327,6 +328,18 @@ func (s *ScanService) run(rootDir, destDir string) {
}
}()
// 收尾必须恢复 stdout 并关闭管道,否则整个进程后续输出都会丢进这根无人读的管道里。
// 用 defer 保证即使 runScan 中途 panic 也不会留下这种状态;panic 还会被接住,
// 转成"出错"状态推给前端,而不是让整个程序崩溃。
defer func() {
os.Stdout = oldStdout
_ = w.Close()
<-done // 等读日志的 goroutine 把剩下的日志读完
if rcv := recover(); rcv != nil {
s.finish(ScanError, fmt.Sprintf("扫描整理内部错误: %v\n%s", rcv, debug.Stack()))
}
}()
// 真正开始干活。期间程序里所有 fmt.Println/Printf 都会进上面的管道
scanErr := s.runScan(rootDir, destDir)