fix: fix ClamAV scan failure issue (#12892)

This commit is contained in:
ssongliu
2026-05-28 18:04:29 +08:00
committed by GitHub
parent 4956b96193
commit f5b47cf74d
7 changed files with 56 additions and 10 deletions

View File

@@ -219,7 +219,7 @@ func (c *CommandHelper) pipeContext() (context.Context, context.CancelFunc) {
func (c *CommandHelper) buildPipeCommands(ctx context.Context, commands []PipeCommand) []*exec.Cmd {
cmds := make([]*exec.Cmd, 0, len(commands))
for _, item := range commands {
cmdItem := exec.CommandContext(ctx, item.Name, item.Args...)
cmdItem := exec.CommandContext(ctx, item.Name, filterEmptyArgs(item.Args)...)
cmdItem.Env = append(os.Environ(), c.env...)
cmdItem.Env = append(cmdItem.Env, item.Env...)
cmdItem.Dir = c.workDir
@@ -284,6 +284,7 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) {
var newContext context.Context
var cancel context.CancelFunc
var outputFile *os.File
arg = filterEmptyArgs(arg)
if c.timeout != 0 {
if c.context == nil {
@@ -378,6 +379,20 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) {
}
}
func filterEmptyArgs(args []string) []string {
if len(args) == 0 {
return args
}
filtered := args[:0]
for _, arg := range args {
if arg == "" {
continue
}
filtered = append(filtered, arg)
}
return filtered
}
func contextDone(ctx context.Context) <-chan struct{} {
if ctx == nil {
return nil