fix: 修复扫描/探测/移动三个健壮性问题
- scanner: filepath.Ext 替代 path.Ext,修复 Windows 点号目录名扩展名解析错误 - scanner: Walk 遇不可访问路径仅告警跳过,不再整体中止扫描 - probe: ffprobe 探测增加 30s 超时,避免损坏文件卡死程序 - mover: copyFile 失败时清理半截目标文件,消除双重 Close - 新增代码审查报告 bug20260814.md
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
package probe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ProbeResult 媒体探测结果(图片/视频/音频通用)
|
||||
@@ -39,9 +41,14 @@ type probeOutput struct {
|
||||
Format formatInfo `json:"format"`
|
||||
}
|
||||
|
||||
// ffprobeTimeout ffprobe 探测超时时间,超时视为探测失败(避免损坏文件卡死程序)
|
||||
const ffprobeTimeout = 30 * time.Second
|
||||
|
||||
// ProbeMediaFile 用 ffprobe 探测媒体文件,一次调用同时获取视频/音频流与时长
|
||||
func ProbeMediaFile(ffprobePath, filePath string) (*ProbeResult, error) {
|
||||
cmd := exec.Command(ffprobePath, "-v", "error",
|
||||
ctx, cancel := context.WithTimeout(context.Background(), ffprobeTimeout)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, ffprobePath, "-v", "error",
|
||||
"-show_entries", "stream=index,codec_type,codec_name,width,height:format=duration,format_name",
|
||||
"-of", "json", filePath)
|
||||
output, err := cmd.Output()
|
||||
|
||||
Reference in New Issue
Block a user